C输入函数scanf
示例
#include<stdio.h>
int main()
{
int input_int = 0;
while(1){
printf("Please input a number between 2 and 1000.\n");
printf("Input:");
scanf("%d", &input_int);
if(input_int >= 2 && input_int <= 1000)
{
break;
}
char c = '\0';
while((c = getchar()) != EOF && c != '\n'){}
if(c == EOF){
printf("Error: can not read a number between 2 and 1000 till end of file.\n");
break;
}
}
return 0;
}