- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check input character is alphabet, digit or special character in C
In this section, we will see how to check whether a given character is number, or the alphabet or some special character in C.
The alphabets are from A – Z and a – z, Then the numbers are from 0 – 9. And all other characters are special characters. So If we check the conditions using these criteria, we can easily find them.
Example
#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"); }
Output
Enter a character: F This is an alphabet
Output
Enter a character: r This is an alphabet
Output
Enter a character: 7 This is a number
Output
Enter a character: # This is a special character
Advertisements