How can I verify that something enetered by a user is a number? I have a program to accept numbers from the user but I need to check each one as they enter them and make sure they are not enetering letters instead.
How can I verify that something enetered by a user is a number? I have a program to accept numbers from the user but I need to check each one as they enter them and make sure they are not enetering letters instead.
Check if scanf() succeed.
or use isdigit() function to check if an input is numbers..Code:#include <stdio.h> #include <stdlib.h> int main(void) { int num; printf("Num: "); if((scanf("%d",&num)) == 1) { //all ok.. right input printf("You entered a number really, %d\n",num); } else { //invalid input.. error handling here printf("You entered, invalid data\n"); printf("Shame on you :)\n"); } system("PAUSE"); return 0; }