69,368
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string.h>
char s[3][20]={
"It is error!",
"It is ok!",
"It may ok.",
};
int main() {
int i;
while (1) {
printf("Input a number(0..2):");
fflush(stdout);
rewind(stdin);
if (1==scanf("%d",&i)) {
if (0<=i && i<=2) {
printf("%s\n",s[i]);
continue;
}
}
printf("Format error!\n");
break;
}
return 0;
}
//Input a number(0..2):0
//It is error!
//Input a number(0..2):1
//It is ok!
//Input a number(0..2):2
//It may ok.
//Input a number(0..2):3
//Format error!
//