【发布时间】:2015-06-30 13:23:27
【问题描述】:
我正在使用 while(getchar()!='\n') 来清空我的标准输入,但有时如果我想继续,我需要按 Enter 键,因此计算继续......为什么?我将发布我的部分代码:
while(1){
if(fgets(buffer,MAX_DIMENSION,stdin)==NULL){ perror("Error"); exit(1);}
}else{
printf("Not correct term\n");
while(getchar()!='\n');
sleep(1);
}
}
谢谢!
@iharob 如果我设置 MAX_DIMENSION=1240 并作为输入发送:a string > 1024 它在标准输入中仍然存在,所以我必须使用 while(getchar()!='\n')
【问题讨论】:
-
为什么这么多人乱用
while (1)?...而且fgets()你也不需要清空任何东西。
标签: c unix fgets enter getchar