C program to check whether a character is uppercase, lowercase, alphabet, digit or special character

Below is the C program to check whether the entered character is uppercase letter, lowercase letter, alphabet, digit or special character.

For that, we will use if-else statement. ASCII value is used to identify the character entered. For example, ASCII value for Uppercase A-Z is 65-90, ASCII value for Lowercase a-z is 97-122, ASCII value for digit 0-9 is 48-57,  and special characters have different series from 0-47, 58-64, 91-96, 123-127.

void main()
char ch;
printf("Please enter a character : ");
scanf("%c",&ch); //

if(ch>=97 && ch<=122)
printf("Entered lower case letter.");
                else if(ch>=48 && ch<=57)
printf("Entered digit.");
                else if(ch>=65 && ch<=90)
printf("\n Entered upper case letter.");
printf("Entered special character.");

Please enter a character : A
Entered Upper case letter.

Post a Comment