C program to check for an alphabet, digit or special character – In this article, we will detail in on the standard method of determining whether any character is an alphabet, digit or a special character.
Suitable examples and sample programs have also been added so that you can understand the whole thing very clearly. The compiler has also been added with which you can execute it yourself.
As you can see, only the standard method is used to define the same.
There are three types of characters used very popularly in the world of information namely:
- Alphabets
- Digits
- Special Characters
All three of these are extremely important in order to move ahead with the scheme of things.
As you can see, everything that is given here comes under the mentioned three categories.
Thus, the way to check for the same in C programming is as follows:
Using Standard Method
1)Read the entered character.
2)If the entered character ASCII value is between 65 to 90 (or) 97 to 122, then it prints “character is alphabet”.otherwise, it checks the next if condition.
3)If the ASCII value is between 48 to 57, then it prints “character is number”.Otherwise, it prints “special character”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include<stdio.h> int main() { char ch; printf("enter character :"); scanf("%c",&ch); if(ch>=65 && ch<=90 || ch>=97 && ch<=122) { printf("character is alphabet"); } else if(ch>=48 && ch<=57) printf("character is number"); else printf("special character"); } |
1 2 3 4 5 6 7 8 |
enter character:4 the character is number enter character :a character is alphabet enter character:? special character |