0

Union in structure : The code is not working with a character as a choice i.e 'y'

struct student { union { char name[15]; int roll; }; int marks; }stud; int main() { char choice; scanf("%c",&choice); switch(choice) { case 'y' : scanf("%s",stud.name); break; default: scanf("%d",&stud.roll); break; } }

11th Jul 2019, 3:27 AM
Sofi Chaudhary
Sofi Chaudhary - avatar
5 odpowiedzi
+ 2
~ swim ~ Look, If I use switch(any integer) it's working otherwise with Character not working
11th Jul 2019, 4:59 AM
Sofi Chaudhary
Sofi Chaudhary - avatar
+ 2
~ swim ~ Thank you 😍😍😍😍
11th Jul 2019, 8:50 AM
Sofi Chaudhary
Sofi Chaudhary - avatar
+ 1
~ swim ~ struct student { union { char name[15]; int roll; }; int marks; }stud; int main() { scanf("%d",&stud.marks); printf("%d",stud.marks); char choice; scanf("%c",&choice); switch(choice) { case 'y' : scanf("%s",stud.name); break; default: scanf("%d",&stud.roll); break; } }
11th Jul 2019, 4:49 PM
Sofi Chaudhary
Sofi Chaudhary - avatar
0
~ swim ~ after run,its gives no output
11th Jul 2019, 8:23 AM
Sofi Chaudhary
Sofi Chaudhary - avatar
0
I tried it on sololearn ~ swim ~ 😅😅😅
11th Jul 2019, 8:41 AM
Sofi Chaudhary
Sofi Chaudhary - avatar