char - Scanning a single character in c -
this question has answer here:
- scanf skips every other while loop in c 10 answers
i have used following code snippet read several values single character constant variable rating not accepting value. doesn't execute particular scanf
statement. how resolve this?
char name[100],locality[100],vision[100],mission[100]; char rating; int dept,stud; printf("enter college name\n"); scanf("%s",name); printf("enter college locality\n"); scanf("%s",locality); printf("enter college's vision\n"); scanf("%s",vision); printf(" enter college's mission\n"); scanf("%s",mission); printf("enter number of departments\n"); scanf("%d",&dept); printf(" enter student strength\n"); scanf("%d",&stud); printf(" enter college rating\n"); scanf("%c",&rating); //not reading value printf("%s\n%s\n",name,locality);
there no compile error or run time error in above code.
when use following code variable accepting value.
char rating; printf(" enter college rating\n"); scanf("%c",&rating);
there nothing wrong code except printf statement of college's mission.
Comments
Post a Comment