R
raseelbhagat
Hi,
I am writing a simple program in which I am using scnaf() twice. The
pseudo code of the program is as follows :
....
printf("Enter lesson no.:");
scanf("%d",lesson);
...
fp = fopen("questions.txt","r");
while(fgets(buf, sizeof(buf), fp) {
fputs(buf, stdout);
}
fclose(fp);
printf("Choose answer\n");
scanf("%c", &c);
if (c == 'A')
printf("Right Answer\n");
else
pritnf("Wrong answer\n");
.....
In the above code, if I don't use the first scanf(), everything works
properly.
Otherwise, after entering an int for the first scanf, the program just
"falls through" without waiting for user input for the second scanf()
and printing "Wrong Answer".
Am I missing out on something here ?
I am writing a simple program in which I am using scnaf() twice. The
pseudo code of the program is as follows :
....
printf("Enter lesson no.:");
scanf("%d",lesson);
...
fp = fopen("questions.txt","r");
while(fgets(buf, sizeof(buf), fp) {
fputs(buf, stdout);
}
fclose(fp);
printf("Choose answer\n");
scanf("%c", &c);
if (c == 'A')
printf("Right Answer\n");
else
pritnf("Wrong answer\n");
.....
In the above code, if I don't use the first scanf(), everything works
properly.
Otherwise, after entering an int for the first scanf, the program just
"falls through" without waiting for user input for the second scanf()
and printing "Wrong Answer".
Am I missing out on something here ?