我正在使用什么scanf() returns when it gets what is expects or when it doesn't. What happens is it gets stuck in the
while()` 循环。
据我所知test = scanf("%d", &testNum);
,如果收到数字则返回 1,否则返回 0。
我的代码:
#include<stdio.h>
int main(void) {
while (1) {
int testNum = 0;
int test;
printf("enter input");
test = scanf("%d", &testNum);
printf("%d", test);
if (test == 0) {
printf("please enter a number");
testNum = 0;
}
else {
printf("%d", testNum);
}
}
return(0);
}