C isalpha() Function Tutorial

  • Post author:
  • Post category:C

In this section, we will learn what the isalpha() function is and how to use it in C.

C isalpha() Function

The `isalpha()` function is used to check whether a character is an `alphabet`. (A-Z or a-z)

The prototype of the function exists in the `ctype.h` header file and we need to include this header file in order to use the ` isalpha ()` function.

isalpha() Function Syntax

Here’s the prototype of the ` isalpha ()` function:

int isalpha (int argument);

isalpha() Function Parameters

This function takes one argument and that is the character that we want to check.

isalpha() Function Return Value

The return value of the function is:

  • 0: If the character was not an `alphabet`.
  • Positive value: if the character was in fact an `alphabet`.

Alpha characters example in C

#include <stdio.h>
#include <ctype.h>

int main() {

    char character = 'a';
    char c2 = '5';

    printf("The first character: %d \nThe second character:%d",isalpha(character),isalpha(c2));

    return  0;
}

Output:

The first character: 2

The second character: 0

The first character in this example is `a` and so the result of calling the `isalpha` function is a positive value because `a` is an alphabet character. But the result of the second character is 0 because the actual value of the character is `5` and it’s not an `alphabet`.

Leave a Reply