I have this code
while(1){
printf("hello world !
");
fgetc(stdin);
}
when this runs and I enter a letter like this:
hello world !
a
it ignores the fgetc(stdin) in the next loop and prints hello world twice without waiting for input.
hello world !
a
hello world !
hello world !
a
hello world !
hello world !
a
hello world !
hello world !
a
hello world !
hello world !
I have tried putting fflush(stdin) before or after the fgetc(stdin) but it still produces the same behaviour, what am I doing wrong ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…