English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

Usage and example of C library function isalnum()

C Standard Library <ctype.h>

If the parameter (character) passed to this function is an alphabetic or numeric character, the isalnum() function will return a non-zero integer.

Function prototype of isalnum()

int isalnum(int argument);

When a character is passed as an argument, it will pass the corresponding ASCII value (integer) of the character, rather than passing the character itself.

This function inIn the ctype.h header fileDefinition.

Example #1: Return value of isalnum( ) function

#include <stdio.h>
#include <ctype.h>
int main()
{
    char c;
    int result;
    c = '5';
    result = isalnum(c);
    printf("Pass %c, the return value is %d\n", c, result);
    c = 'Q';
    result = isalnum(c);
    printf("Pass %c, the return value is %d\n", c, result);
    c = 'l';
    result = isalnum(c);
    printf("Pass %c, the return value is %d\n", c, result);
    c = '+';
    result = isalnum(c);
    printf("Pass %c, the return value is %d\n", c, result);
    return 0;
}

Output Result

Pass 5 When, the return value is 1
Pass Q, the return value is 1
Pass l, the return value is 1
Pass + When, the return value is 0

Example #2Check if the character is an alphabetic or numeric character

#include <stdio.h>
#include <ctype.h>
int main()
{
    char c;
    printf("Enter a character: ");
    scanf("%c", &c);
    if (isalnum(c) == 0)
        printf("%c is not an alphanumeric character.", c);
    else
        printf("%c is a alphanumeric character.", c);
    
    return 0;
}

Output Result

Enter a character: 0
0 is a alphanumeric character.

C Standard Library <ctype.h>