#include <stdio.h>
int main()
{
char another;
int num;
do
{
printf("enter the number");
scanf("%d", &num);
printf("square of%d is %d\n", num, num * num);
printf("want to check another number y/n");
fflush(stdin);
scanf("%c", &another);
} while (another == 'y');
return 0;
}
上面的代码中,第二个scanf()
没有被执行,因此控制台不接受输入。
最佳答案
根据标准,刷新stdin
为undefined behaviour 。请参阅Using fflush(stdin)
了解更多信息。
关于c - 为什么 scanf 在这里跳过输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42910246/