C Library - isalpha() Function
The C ctype library isalpha() function is used to check if a given character is an alphabetic letter or not. If argument c is not an alphabetic letter, the function returns 0 (false).
Syntax
Following is the C library syntax of the isalpha() function −
int isalpha(int c);
Parameters
This function accepts a single parameter −
c − This is the character to be checked, passed as an int. The value of c must be representable as an unsigned char or must be equal to EOF.
Return Value
The function returns a non-zero value (true) if the character c is an alphabetic letter (either uppercase or lowercase), which means it falls within the ranges A to Z or a to z.
Example 1: Checking a Single Alphabetic Character
We will take a alphabetic letter form the Character set A-Z and then check if the letter is recognized as an alphabet or not by isalpha() function.
#include <stdio.h>
#include <ctype.h>
int main() {
char c = 'A';
if (isalpha(c)) {
printf("%c is an alphabetic character.\n", c);
} else {
printf("%c is not an alphabetic character.\n", c);
}
return 0;
}
Output
The above code produces following result −
A is an alphabetic character.
Example 2: Checking a special character
In this example, we check if a special character is also recognized as a alphabetic character or not.
#include <stdio.h>
#include <ctype.h>
int main() {
char c = '@';
if (isalpha(c)) {
printf("%c is an alphabetic character.\n", c);
} else {
printf("%c is not an alphabetic character.\n", c);
}
return 0;
}
Output
The above code produces following result −
@ is not an alphabetic character.