这是一种模拟C语言中fflush函数的方法,能清理空缓冲区不符合输入要求的垃圾数据
但是C语言的自带函数更好,我们赞成直接使用函数
#include<stdio.h>
int main(int argc, int **args)
{
int n;
while (!scanf("%d", &n)) {
while (getchar() != '\n');
printf("\n请重新输入\n");
}
printf("%d", n);
}
不懂的请留言
这是一种模拟C语言中fflush函数的方法,能清理空缓冲区不符合输入要求的垃圾数据
但是C语言的自带函数更好,我们赞成直接使用函数
#include<stdio.h>
int main(int argc, int **args)
{
int n;
while (!scanf("%d", &n)) {
while (getchar() != '\n');
printf("\n请重新输入\n");
}
printf("%d", n);
}
不懂的请留言