The following simple program would give an endless loop when the input is a character, though it meant to tell a character from a digit. How to test if scanf
gets a character when it is supposed to be a digit using the return value of scanf
?
#include <stdio.h>
int main() {
int n;
int return_value = 0;
while (!return_value) {
printf("Input a digit:");
return_value = scanf("%d", &n);
}
printf("Your input is %d\n", n);
return 0;
}