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

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

The isalnum() 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 alphanumeric, and zero otherwise.

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

ref‮:ot re‬theitroad.com
#include <stdio.h>
#include <ctype.h>

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

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

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