isalpha()

In C programming, isalpha() function checks whether a character is an alphabet(a to z and A-Z) or not. If a character passed to isalpha() is an alphabet, it returns non-zero integer if not it returns 0.

Defined in Header file: <ctype.h>

Function Prototype of isalpha()

int isalpha(int argument);

Function isalpha() takes single argument in form of an integer and returns integer value. Even though, isalpha() takes integer as an argument, character is passed to isalpha() function. When character is passed as an argument, corresponding ASCII value of that character is passed instead of that character itself.

Example to Demonstrate the Working of isalpha()

#include <stdio.h>
#include <ctype.h>
int main()
{
    char c;
    c='Q';
    printf("\nResult when uppercase alphabet is passed: %d",isalpha(c));
    c='q';
    printf("\nResult when lowercase alphabet is passed: %d",isalpha(c));
    c='+';
    printf("\nResult when non-alphabetic character is passed: %d",isalpha(c));
    return 0;
}

Output

Result when uppercase alphabet is passed: 1
Result when lowercase alphabet is passed: 2
Result when non-alphabetic character is passed: 0

Note: You can get different non-zero integer when alphabetic character is passed to isalpha() on you system. But, when you pass non-alphabetic character to isalpha(), it always returns 0.

C Program to Check whether a Character Entered by User is Alphabet or not

#include <stdio.h>
#include <ctype.h>
int main()
{
    char c;
    printf("Enter a character: ");
    scanf("%c",&c);
    if (isalpha(c)==0)
    {
         printf("%c is not an alphabet.",c);
    }
    else
         printf("%c is an alphabet.",c);
    return 0;
}

Output

Enter a character: 5
5 is not an alphabet.