isalpha in C Programming

The C isalpha is a Standard Library Function, which is useful to check whether the given character is an alphabet or not. The syntax of the C isalpha accepts a single character as the parameter and checks whether it is an alphabet or not.

isalpha(char)

isalpha in C Programming Example

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

First, we declared a character variable called ch. The following C Programming printf statement will ask the user to enter. And then, we use the scanf to assign the user entered one to ch variable.

In this next line, we added the If Statement to check whether the character is between ‘A’ and ‘Z’ using the C isalpha function. If the condition is True, the printf statement inside the if block will print.

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

#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

The above C isalpha code will definitely check whether the given character is an alphabet or not, but what if we enter the numeric value? Please refer to C Program to check whether Alphabet or Not. It helps how to check whether the char 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