#include <ctype.h> int isalnum(int c);
isalnum
tests an integer value to determine whether it is an
alphabetic (uppercase or lowercase) or numeric character.
isalnum
returns 0 if the character is not alphanumeric, or a nonzero
value if it is alphanumeric. If the argument is EOF
, 0 is returned.
isalnum
on a noncharacter argument other than EOF
is undefined. Do not assume that isalnum
returns either 0 or 1.
#include <ctype.h> #include <stdio.h> #define MAXLEN 40 main() { char id[MAXLEN+1]; int i; char *text; char input[MAXLEN]; puts("Enter a string of characters (40 at most)."); text = gets(input); puts("Initial alphanumeric characters you entered are:"); for (i = 0; i < MAXLEN && isalnum(text[i]); i++) { id[i] = text[i]; putc(id[i]); } id[i] = '0'; putc('n'); }
isalpha
, isdigit
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.