Check if input character is letter, number or special character in C

PHPz
Release: 2023-09-01 23:29:05
forward
1316 people have browsed it

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.

Example

#include  #include  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"); }
Copy after login

Output

Enter a character: F This is an alphabet
Copy after login

Output

Enter a character: r This is an alphabet
Copy after login

Output

Enter a character: 7 This is a number
Copy after login

Output

Enter a character: # This is a special character
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!