The isalpha() function defined in the ctype.h header file. It helps to check the specified character is alphabet(a to z and A-Z) or not.
int isalpha(int argument); #where argument will be a character
The isalpha() function takes a single parameter and is in the form of an integer and the return value should be an integer. When a character is passed it is converted into the integer value corresponding to its ASCII value.
Parameter | Description | Required / Optional |
---|---|---|
argument | The character to be checked | Required |
If the given character is an alphabet, isalpha() returns a non-zero integer else zero.When an alphabetic character is passed we will get a different non-zero integer.
Input | Return Value |
---|---|
Zero | If the parameter isn't an alphabet |
Non zero number | If the parameter is an alphabet |
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
ch = 'A';
printf("\nIf uppercase alphabet is passed: %d", isalpha(ch));
ch = 'a';
printf("\nIf lowercase alphabet is passed: %d", isalpha(ch));
ch='+';
printf("\nIf non-alphabetic character is passed: %d", isalpha(ch));
return 0;
}
Output:
If uppercase alphabet is passed: 1 If lowercase alphabet is passed: 2 If non-alphabetic character is passed: 0
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
printf("Please enter a character: ");
scanf("%c", &ch;);
if (isalpha(ch) == 0)
printf("The given %c is not an alphabet.", ch);
else
printf("The given %c is an alphabet.", ch);
return 0;
}
Output:
Please enter a character: 10 The given 10 is not an alphabet.