scanf()
returns the number of successful arguments. If you do:
int ivar, return_val;
return_val = scanf("%i", &ivar);
return_val
should be 1, cause of 1 parameter (ivar
). Check the user input:
if (return_val == 1) {
// right input
} else {
// wrong input
}