Rather than trying to work out that it's not a character, work out that it is a digit and discard the rest using the isdigit function from ctype like below.
#include <ctype.h>
...
if (isdigit(num)) {
printf("You entered %d\n", num);
}
But this only works on single characters which is quite useless when you read in strings. So instead you could instead use the function sscanf. Like this.
int num;
if (sscanf(numstr, "%d", &num)){
printf("You entered %d\n", num);
} else {
printf("Invalid input '%s'\n", numstr);
}
Another option is to use the atoi function. But as I recall it doesn't handle errors and I find quite inferior to sscanf.
-as a character ahead.int num; if (scanf("%d", &num) == 1 && !islower(num)) printf("You entered %d\n", num);(noting the newline in the output). If the input is inherently non-numeric, thescanf()will fail; if the input is numeric but in the range of lower-case letters (97..122 in codesets derived from ISO 8859), then it will not be accepted. If you're usingint num = getchar();to read a single character, the answer is somewhat different.