#include <stdio.h>
int main(){
int inpt,
pos = 0,
neg = 0,
zero = 0;
char cont = 'y';
while(cont == 'y' || cont == 'Y') {
printf("\nPlease enter a Number: ");
scanf("%d", &inpt);
if( inpt < 0) {
neg++;
} else if( inpt > 0) {
pos++;
} else {
zero++;
}
fflush(stdin);
printf("\n Do you want to Continue:");
scanf("%c", &cont);
printf("\nvalue: %d", cont);
}
printf("\nTotal Number of Positive Integers: %d \n Total Number of Negative Integers: %d \n Total Number of Zeros: %d ", pos, neg, zero);
return 0;
}
[幸运的是,我尝试调试并打印了cont的值,发现它的值为10(这是键盘中Enter键的ASCII值)。我希望fflush应该清除了输入缓冲区,但事实并非如此。
关于如何修复的任何建议将不胜感激。
下面是一个我正在尝试运行的简单程序,但是很遗憾,它无法正常运行,当我第二次尝试输入时,它不会接受输入。 #include
int main(){...
%*c
放弃缓冲区剩余的\n
字符。