c语言中限制用户输入整数
#include <stdio.h> long get_long(void); int main(void) { long num; printf("please input an num: "); num = get_long(); printf("num: %ld.\n", num); return 0; } long get_long(void) { long input; char ch; while(scanf("%d", &input) != 1) { while((ch = getchar())!= '\n') putchar(ch); printf(" is not num.\n"); printf("please input num: "); } return input; }