每当我在 fgets 之前执行 scanf 时,都会跳过 fgets 指令。我在 C++ 中遇到过这个问题,我记得我必须有一些指令来清除标准输入缓冲区或类似的东西。我想C有一个等价物。它是什么?
谢谢。
我敢打赌这是因为 \n 卡在输入流中。
请参阅以下问题之一:
我无法刷新标准输入。
我如何在这里进行法拉盛 STDIN?
scanf() 导致无限循环
或这个答案。
另外:为什么不使用 scanf()。
PSfgets()
是一个函数,而不是一个指令。
You can just put this line before your fgets()
call and that'll get the trailing '\n'
generated when you pressed enter
scanf("%c", (char *) stdin);