我有这个代码
while(1){
printf("hello world !\n");
fgetc(stdin);
}
Run Code Online (Sandbox Code Playgroud)
当它运行时,我输入这样的字母:
hello world !
a
Run Code Online (Sandbox Code Playgroud)
它忽略了下一个循环中的fgetc(stdin)并打印了两次hello world而不等待输入.
hello world !
a
hello world !
hello world !
a
hello world !
hello world !
a
hello world !
hello world !
a
hello world !
hello world !
Run Code Online (Sandbox Code Playgroud)
我试过在fgetc(stdin)之前或之后放fflush(stdin),但它仍然会产生相同的行为,我做错了什么?