isalpha function(Test for Alphabetic) in C Language – example and detail

In the C Programming Language, the isalpha characteristic checks whether c is alphabetic.

Syntax

The syntax for the isalpha function in the C Language is:

int isalpha(int c);

Parameters or Arguments

c

The value to test whether it is alphabetic.

Note c is regarded to be alphabetic if both islower(c) is genuine or isupper(c) is true.

Returns

The isalpha feature returns a nonzero cost if c is alphabetic and returns zero if c is no longer alphabetic.

Required Header

In the C Language, the required header for the isalpha characteristic is:

#include <ctype.h>

Applies To

In the C Language, the isalpha function can be used in the following versions:

ANSI/ISO 9899-1990

isalpha Example

/* Example using isalpha by TechOnTheNet.com */

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

int main(int argc, const char * argv[])
{
    /* Define a temporary variable */
    unsigned char test;

    /* Assign a test letter to the variable */
    test = 'T';

    /* Test to see if this is a alphabet character */
    if (isalpha(test) != 0) printf("%c is in the alphabet\n", test);
    else printf("%c is not in the alphabet\n", test);

    /* Assign a non-alphabetic character to the variable */
    test = '7';

    /* Test to see if this is a alphabet character */
    if (isalpha(test) != 0) printf("%c is in the alphabet\n", test);
    else printf("%c is not in the alphabet\n", test);

    return 0;
}

When compiled and run, this application will output:

T is in the alphabet
7 is not in the alphabet

Similar Functions

Other C functions that are similar to the isalpha function:

isalnum feature islower function isupper function

See Also

Other C functions that are noteworthy when dealing with the isalpha function:

tolower characteristic toupper characteristic