isalpha in C Programming

The C isalpha function is one of the Standard Library Functions, which is useful to check the given character is an alphabet or not. The syntax of the isalpha in C Programming language is shown below. The below isalpha function accepts a single character as the parameter and check whether the given character is an alphabet or not.

isalpha(char)

isalpha in C Programming Example

The isalpha method used to find the given character is an alphabet or not. This program allows the user to enter any character. Next, it checks whether the character is between A to Z, or a to z using the isalpha function.

//Example for isalpha in C Programming
#include <stdio.h>
#include <ctype.h>

int main()
{
    char ch;
    printf("Please Enter Any Valid Character: \n");
    scanf("%c", &ch);

    if(isalpha(ch))
    {
      printf("\n You have entered an Alphabet");         
    }
    else
    {
      printf("\n %c is not an Alphabet", ch);
      printf("\n I request you to enter Valid Alphabet");	
    }
}
isalpha in C Programming 1

Let me enter the Uppercase letter

Please Enter Any Valid Character: 
H

 You have entered an Alphabet

First, we declared a character variable called ch

char ch;

The following C Programming statement will ask the user to enter any character. And then, we use the scanf to assign the user entered character to ch variable

printf("Please Enter Any Valid Character: \n");
scanf("%c", &ch);

In this next line, we added the If Statement to check whether the character is between ‘A’ and ‘Z’ using C isalpha function. If the condition is True, then the following statement will be printed

printf("\n You have entered an Alphabet");

If the above condition is FALSE, then the given character is not Alphabet. So, it will print below statements

printf("\n %c is not an Alphabet", ch);
printf("\n I request you to enter Valid Alphabet");

The above code will definitely check whether the given character is an alphabet or not, but what if we enter the numeric value. Please refer C Program to check whether the Character is Alphabet or Not to know how to check the character is alphabet without using the isalpha function

Please Enter Any Valid Character: 
9

 9 is not an Alphabet
 I request you to enter Valid Alphabet