English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Comprehensive Collection of C Programming Examples
C program checks if a character is a letter
In this example, you will learn to check if the character entered by the user is a letter.To understand this example, you should understand the followingC language programming
C if ... else statement127In C language programming, a character variable saves the ASCII value (0 to
integer), not the character itself.97or122The ASCII value of lowercase letters is65or90.
The ASCII value of uppercase letters is97or122If the ASCII value of the character entered by the user is within65or90 to
#include <stdio.h> int main() { char c; printf("Enter a character: "); scanf("%c", &c); if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) printf("%c is a letter.", c); else printf("%c is not a letter.", c); return 0; }
Output Result
Enter a character: * * Is not a letter.
In the program, replace with 'a'.97Replace with 'z'.122Similarly, replace with 'A'.65Replace with 'Z'.90.
Note:Suggested to use this isalpha() function to check if a character is a letter.