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; } }
10 Réponses
+ 2
~ swim ~ Look, If I use switch(any integer) it's working otherwise with Character not working
+ 2
~ swim ~ Thank you 😍😍😍😍
+ 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;
}
}
0
~ swim ~ after run,its gives no output
0
I tried it on sololearn ~ swim ~ 😅😅😅