Home >Backend Development >C++ >Check if input character is letter, number or special character in C
In this section, we will see how to check whether a given character is a number, letter or some special character in C.
The alphabet is from A – Z and a – z, then the numbers are 0 – 9. All other characters are special characters. So if we check the conditions using these we can find them easily.
#include <stdio.h> #include <conio.h> main() { char ch; printf("Enter a character: "); scanf("%c", &ch); if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) printf("This is an alphabet"); else if(ch >= '0' && ch <= '9') printf("This is a number"); else printf("This is a special character"); }
Enter a character: F This is an alphabet
Enter a character: r This is an alphabet
Enter a character: 7 This is a number
Enter a character: # This is a special character
The above is the detailed content of Check if input character is letter, number or special character in C. For more information, please follow other related articles on the PHP Chinese website!