【发布时间】:2011-02-21 05:25:54
【问题描述】:
我有一个非常短的 sn-p,它读取一个整数:
#include <stdio.h>
int main() {
while (1) {
int i = 0;
int r = scanf("%d", &i);
if (r == EOF) {
printf("Error using scanf()\n");
} else if (r == 0) {
printf("No number found\n");
} else {
printf("The number you typed in was %d\n", i);
}
}
}
但问题是,如果我输入任何字母,它只会不断循环并打印出“未找到数字”,而不是等待下一个输入。
我做错了什么?
【问题讨论】: