Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

isalnum — C23 character classification function

`isalnum(c)` from `<ctype.h>` returns a nonzero value when `c` is a letter or a decimal digit in the current locale, equivalently when `isalpha(c) || isdigit(c)` would be true. Otherwise it returns zero; the particular nonzero value need not be 1.

Version: C23

Syntax

int isalnum(int c);

isalnum(c) from <ctype.h> returns a nonzero value when c is a letter or a decimal digit in the current locale, equivalently when isalpha(c) || isdigit(c) would be true. Otherwise it returns zero; the particular nonzero value need not be 1.

The example classifies A, 7, -, and space in the initial C locale, normalizing each result with != 0. Output 1 1 0 0 shows that the letter and digit are alphanumeric while punctuation and whitespace are not.

The argument must be EOF or a value representable as unsigned char; passing a negative plain char has undefined behavior. For bytes from text, use isalnum((unsigned char)ch) while handling EOF separately. The answer depends on LC_CTYPE, so do not use this byte function to classify Unicode code points or validate locale-independent identifiers.

Examples

#include <ctype.h>
#include <stdio.h>
int main(void){int values[]={'A','7','-',' '};printf("%d %d %d %d\n",isalnum(values[0])!=0,isalnum(values[1])!=0,isalnum(values[2])!=0,isalnum(values[3])!=0);return 0;}

Result

1 1 0 0

The example classifies `A`, `7`, `-`, and space in the initial `C` locale, normalizing each result with `!= 0`. Output `1 1 0 0` shows that the letter and digit are alphanumeric while punctuation and whitespace are not.

Sources