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 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 C isalpha function. If the condition is True, then the printf statement inside the if block will be printed

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

//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

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 Alphabet or Not to know how to check the it 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