7.4.3 <ctype.h>

Checks and converts character types.

Type

Definition Name

Description

Function

isalnum

Tests for a letter or a decimal digit.

isalpha

Tests for a letter.

iscntrl

Tests for a control character.

isdigit

Tests for a decimal digit.

isgraph

Tests for a printing character except space.

islower

Tests for a lowercase letter.

isprint

Tests for a printing character including space.

ispunct

Tests for a special character.

isspace

Tests for a white-space character.

isupper

Tests for an uppercase letter.

isxdigit

Tests for a hexadecimal digit.

tolower

Converts an uppercase letter to lowercase.

toupper

Converts a lowercase letter to uppercase.

isblank <-lang=c99>

Tests for a space character or a tab character.

In the above functions, if the input parameter value is not within the range that can be represented by the unsigned char type and is not EOF, the operation of the function is not guaranteed.

Character types are listed in table 6.5.

Table 7.6

Character Types

Character Type

Description

Uppercase letter

Any of the following 26 characters

'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'

Lowercase letter

Any of the following 26 characters

'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'

Letter

Any uppercase or lowercase letter

Decimal digit

Any of the following 10 characters

'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'

Printing character

A character, including space (' ') that is displayed on the screen (corresponding to ASCII codes 0x20 to 0x7E)

Control character

Any character except a printing character

White-space character

Any of the following 6 characters

Space (' '), form feed ('\f'), new-line (’\n’), carriage return (’\r’), horizontal tab (’\t’), vertical tab (’\v’)

Hexadecimal digit

Any of the following 22 characters

’0’, ’1’, ’2’, ’3’, ’4’, ’5’, ’6’, ’7’, ’8’, ’9’,
’A’, ’B’, ’C’, ’D’, ’E’, ’F’, ’a’, ’b’, ’c’, ’d’, ’e’, ’f’

Special character

Any printing character except space (’ ’), a letter, or a decimal digit

Blank character

Either of the following 2 characters

Space (’ ’), horizontal tab (’\t’)

Implementation-Defined Specifications

Item

Compiler Specifications

The character set inspected by the isalnum, isalpha, iscntrl, islower, isprint, and isupper functions

Character set represented by the unsigned char type (0 to 255) and EOF (-1). Table 7.7 shows the character set that results in a true return value.

 

Table 7.7

True Character

Function Name

True Characters

isalnum

'0' to '9', 'A' to 'Z', 'a' to 'z'

isalpha

'A' to 'Z', 'a' to 'z'

iscntrl

'\x00' to '\x1f', '\x7f'

islower

'a' to 'z'

isprint

'\x20' to '\x7E'

isupper

'A' to 'Z'

 

isalnum

Tests for a letter or a decimal digit.

[Format]

#include <ctype.h>
long isalnum (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a letter or a decimal digit: Nonzero
If character c is not a letter or a decimal digit: 0

isalpha

Tests for a letter.

[Format]

#include <ctype.h>
long isalpha(long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a letter: Nonzero
If character c is not a letter: 0

 

iscntrl

Tests for a control character.

[Format]

#include <ctype.h>
long iscntrl (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a control character: Nonzero
If character c is not a control character: 0

 

isdigit

Tests for a decimal digit.

[Format]

#include <ctype.h>
long isdigit (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a decimal digit: Nonzero
If character c is not a decimal digit: 0

 

isgraph

Tests for any printing character except space (’ ’).

[Format]

#include <ctype.h>
long isgraph (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a printing character except space: Nonzero
If character c is not a printing character except space: 0

 

islower

Tests for a lowercase letter.

[Format]

#include <ctype.h>
long islower (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a lowercase letter: Nonzero
If character c is not a lowercase letter: 0

 

isprint

Tests for a printing character including space (’ ’).

[Format]

#include <ctype.h>
long isprint (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a printing character including space: Nonzero
If character c is not a printing character including space: 0

 

ispunct

Tests for a special character.

[Format]

#include <ctype.h>
long ispunct (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a special character: Nonzero
If character c is not a special character: 0

 

isspace

Tests for a white-space character.

[Format]

#include <ctype.h>
long isspace (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a white-space character: Nonzero
If character c is not a white-space character: 0

 

isupper

Tests for an uppercase letter.

[Format]

#include <ctype.h>
long isupper (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is an uppercase letter: Nonzero
If character c is not an uppercase letter: 0

 

isxdigit

Tests for a hexadecimal digit.

[Format]

#include <ctype.h>
long isxdigit (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a hexadecimal digit: Nonzero
If character c is not a hexadecimal digit: 0

 

tolower

Converts an uppercase letter to the corresponding lowercase letter.

[Format]

#include <ctype.h>
long tolower (long c);

[Parameters]

c Character to be converted

[Return values]

If character c is an uppercase letter: Lowercase letter corresponding to character c

If character c is not an uppercase letter: Character c

 

toupper

Converts a lowercase letter to the corresponding uppercase letter.

[Format]

#include <ctype.h>
long toupper (long c);

[Parameters]

c Character to be converted

[Return values]

If character c is a lowercase letter: Uppercase letter corresponding to character c

If character c is not a lowercase letter: Character c

 

isblank

Tests for a space character or a tab character.

[Format]

#include <ctype.h>
long isblank (long c);

[Parameters]

c Character to be tested

[Return values]

If character c is a space character or a tab character: Nonzero
If character c is neither a space character nor a tab character: 0