Thread: Error Trapping
View Single Post
Mentor
29Jul2012,13:35  
xpi0t0s's Avatar
You would have to read the input into a string variable, then check if it's a valid number with a function like atoi(), and if not, throw a suitable error.
Code:
char buf[32];
fgets(buf,30,stdin); // order of params might be wrong
int num=atoi(buf);
if (num<3 || num>9) printf("Wrong\n");