I'm writing a program which allows user to enter alphanumeric strings and validate their input based on the options available.when I run my code below, it always print option is invalid even though I have entered an option within the range.Can anyone help me with this?Any help will be aprreciated.
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main (void){
char option;
do{
printf("\n\n----------------------------------------------------\n");
printf("Main Menu\n");
printf("----------------------------------------------------\n");
printf("1. Add Record\n");
printf("2. Delete record\n");
printf("3. List Record\n");
printf("4. Exit\n");
printf("----------------------------------------------------\n");
printf("Enter your option:");
scanf("%c",&option);
if(isdigit(option)){
switch(option){
case 1:
add();
break;
case 2:
del();
break;
case 3:
listrec();
break;
case 4:
return 0;
default:
printf("The number that you have entered is invalid.Please enter a new option\n");
break;
}
else{
printf("The option that you have entered is invalid.Please enter a new option\n");
}
}while(option!=4);
return 0;
}
case 1:-->case '1':option - '0'will always work, whileoption - '48'is character set dependent.