I was experimenting with C's fgetc()
and ran into a strange problem.
I typed the following code below:
int answer = 0;
printf("Input1\n");
answer = fgetc(stdin);
printf("%c\n", answer);
printf("Input2\n");
answer = fgetc(stdin);
printf("%c\n", answer);
However, every time I enter a value other than a space, this happens:
Input1
1
1
Input2 # It doesn't wait for my input here
Could anyone tell me what I'm doing wrong? I've tried flushing stdin
and I've also tried using rewind
on stdin
. However, none of these work.