I am going to assume that you are using scanf
to handle input. the program should not crash. You need to read the manual page for scanf and in the section return values it tells you that the function returns the number of items matched. You compare this number with what is expected. If they differ you take the appropriate action.
EDIT
Some code for Matthew and Bart:
int i;
if (scanf("%d", &i) == 1)
{
printf("You have entered %d\n", i);
}
else
{
printf("You have entered an invalid number\n");
}