我在 while 循环中使用了 scanf()。
while(1)
{
int input = 0;
scanf("%d\n", &input);
printf("%d\n", input);
}
当我运行这个程序并输入一个数字时,除非我再次输入另一个数字,否则 printf()
不会显示该数字。为什么?
最佳答案
scanf
格式中的 \n
被解释为“任意数量的空白”。它会不断读取空格(空格、制表符或回车符),直到遇到不是空格的内容。
关于c - 为什么 scanf 卡在 while 循环中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17518290/