You should use scanf
return value. From man scanf:
Return Value
These functions return the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.
So it may look like this:
if (scanf("%d", &num) != 1)
{
/* Display error message. */
}
Notice it doesn't work for "numbers with the decimal point". For this you should rather use parsing and strtol
for instance. It may be a bit more complex.