isalnum Function

Test for an alphanumeric character.

Include

<ctype.h>

Prototype

int isalnum(int c);

Argument

c
The character to test.

Return Value

Returns a non-zero integer value if the character, c, is alphanumeric; otherwise, returns a zero.

Remarks

Alphanumeric characters are included within the ranges 'A'-'Z', 'a'-'z' or '0'-'9'.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <ctype.h>
#include <stdio.h>

int main(void)
{
  int ch;

  ch = '3';
  if (isalnum(ch))
    printf("3 is an alphanumeric\n");
  else
    printf("3 is NOT an alphanumeric\n");
 
  ch = '#';
  if (isalnum(ch))
    printf("# is an alphanumeric\n");
  else
    printf("# is NOT an alphanumeric\n");
}

Example Output

3 is an alphanumeric
# is NOT an alphanumeric