is Functions >

Description

Test characters for specified conditions.

#include <ctype.h>

int isalnum( int c );

int isalpha( int c );

int __isascii( int c );

int iscntrl( int c );

int __iscsym( int c );

int __iscsymf( int c );

int isdigit( int c );

int isgraph( int c );

int islower( int c );

int isprint( int c );

int ispunct( int c );

int isspace( int c );

int isupper( int c );

int isxdigit( int c );

c Integer to be tested  

Remarks

Each function in the is family tests a given integer value, returning a nonzero value if the integer satisfies the test condition and 0 if it does not. The ASCII character set is assumed.

The is functions and their test conditions are listed below:

Function Test Condition

isalnum Alphanumeric ('A'–'Z', 'a'–'z', or '0'–'9')
isalpha Letter ('A'–'Z' or 'a'–'z')
__isascii ASCII character (0x00–0x7F)
iscntrl Control character (0x00–0x1F or 0x7F)
__iscsym Letter, underscore, or digit
__iscsymf Letter or underscore
isdigit Digit ('0'–'9')
isgraph Printable character except space (' ')
islower Lowercase letter ('a'–'z')
isprint Printable character (0x20–0x7E)
ispunct Punctuation character
isspace White-space character (0x09–0x0D or 0x20)
isupper Uppercase letter ('A'–'Z')
isxdigit Hexadecimal digit ('A'–'F','a'–'f', or '0'–'9')

The __isascii routine produces meaningful results for all integer values. However, the remaining routines produce a defined result only for integer values corresponding to the ASCII character set (that is, only where __isascii holds true) or for the non-ASCII value EOF (defined in STDIO.H).

These routines are implemented both as functions and as macros. For details on choosing a function or a macro implementation, see “Choosing Between Functions and Macros”.

Return Value

These routines return a nonzero value if the integer satisfies the test condition and 0 if it does not.

Compatibility

isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, isupper, isxdigit

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

__isascii

Standards:UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

Use __isascii for compatibility with ANSI naming conventions of non-ANSI functions. Use isascii and link with OLDNAMES.LIB for UNIX compatibility.

__iscsym, __iscsymf

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

__toascii, tolower, toupper functions

Example

/* ISFAM.C: This program tests all characters between 0x0 and 0x7F,

* then displays each character with abbreviations for the character-type

* codes that apply.

*/

#include <stdio.h>

#include <ctype.h>

void main( void )

{

int ch;

for( ch = 0; ch <= 0x7F; ch++ )

{

printf( “%.2x ”, ch );

printf( “ %c”, isprint( ch ) ? ch : '\0' );

printf( “%4s”, isalnum( ch ) ? “AN” : “” );

printf( “%3s”, isalpha( ch ) ? “A” : “” );

printf( “%3s”, __isascii( ch ) ? “AS” : “” );

printf( “%3s”, iscntrl( ch ) ? “C” : “” );

printf( “%3s”, __iscsym( ch ) ? “CS ” : “” );

printf( “%3s”, __iscsymf( ch ) ? “CSF” : “” );

printf( “%3s”, isdigit( ch ) ? “D” : “” );

printf( “%3s”, isgraph( ch ) ? “G” : “” );

printf( “%3s”, islower( ch ) ? “L” : “” );

printf( “%3s”, ispunct( ch ) ? “PU” : “” );

printf( “%3s”, isspace( ch ) ? “S” : “” );

printf( “%3s”, isprint( ch ) ? “PR” : “” );

printf( “%3s”, isupper( ch ) ? “U” : “” );

printf( “%3s”, isxdigit( ch ) ? “X” : “” );

printf( “\n” );

}

}

Output

00 AS C

01 AS C

02 AS C

.

.

.

38 8 AN AS CS D G PR X

39 9 AN AS CS D G PR X

3a : AS G PU PR

3b ; AS G PU PR

3c < AS G PU PR

3d = AS G PU PR

3e > AS G PU PR

3f ? AS G PU PR

40 @ AS G PU PR

41 A AN A AS CS CSF G PR U X

42 B AN A AS CS CSF G PR U X

.

.

.