C Standard Library

C <ctype.h> - isalnum() Function



The C <ctype.h> isalnum() function is used to check if the given character is an alphanumeric letter. An alphanumeric letter is either a decimal digit or an uppercase or lowercase letter. In the default "C" locale, an alphanumeric letter is a letter for which either isdigit or isupper or islower function returns true. Other locales may consider a different selection of characters as alphanumeric letters.

Syntax

int isalnum ( int ch );               

Parameters

ch Specify the character to be checked, casted to an int, or EOF.

Return Value

Returns non-zero value (i.e, true) if ch is an alphanumeric letter, else returns zero (i.e, false).

Example:

The example below shows the usage of isalnum() function.

#include <stdio.h>
#include <ctype.h>
 
int main (){
  char str[50] = "98Hi@@";

  //counting the numbers of 
  //alphanumeric letters in str
  int i = 0, count = 0;
  while(str[i]) {
    if(isalnum(str[i]))
      count++;
    i++;
  }

  //displaying the output
  printf("%s contains %d alphanumeric letters.", str, count); 
  return 0;
}

The output of the above code will be:

98Hi@@ contains 4 alphanumeric letters.

❮ C <ctype.h> Library