C programming ctype.h function - int isalpha(int c)

The int isalpha(int c) function in the ctype.h library of C programming is used to determine whether a given character is an alphabetic character. An alphabetic character is a character that is either a letter (uppercase or lowercase).

The isalpha() function takes a single integer argument c, which is the character to be checked. The function returns an integer value, which is nonzero if the character is alphabetic, and zero otherwise.

Here's an example of how to use the isalpha() function in C:

refer to:‮ditfigi‬ea.com
#include <stdio.h>
#include <ctype.h>

int main() {
    char c = 'a';
    if (isalpha(c)) {
        printf("%c is alphabetic\n", c);
    } else {
        printf("%c is not alphabetic\n", c);
    }
    return 0;
}

In this example, the isalpha() function is used to check whether the character 'a' is alphabetic. Since 'a' is a letter, the function returns a nonzero value, and the output will be: a is alphabetic.

If the character had been a non-alphabetic character such as '$', the isalpha() function would return zero, and the output would be: '$' is not alphabetic.