Chapter 3. Character Handling <ctype.h>

Table of Contents
3.1. Character Testing Functions
3.2. Character Case Mapping Functions

The header <ctype.h> declares several functions useful for testing and mapping characters. In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall be equal to the value of the macro EOF. If the argument has any other value, the behavior is undefined.

The behavior of these functions is effected by the current locale[1]. Those functions that have implementation-defined aspects only when not in the "C" locale are noted below.

The term printing character refers to a member of an implementation-defined set of characters, each of which occupies one printing position on a display device: the term control character refers to a member of an implementation-defined set of characters that are not printing characters.

Implementation Notes

3.1. Character Testing Functions

3.1.1. The isalnum function

Synopsis
#include <ctype.h>

int isalnum (int c );

Description

The isalnum function tests for any character for which isalpha or isdigit is true.

3.1.2. The isalpha function

Synopsis
#include <ctype.h>

int isalpha (int c );

Description

The isalpha function tests for any character for which isupper or islower is true, or any character that is one of an implementation-defined set of characters for which non of iscntrl, isdigit, ispunct, or isspace is true. In the "C" locale, isalpha returns true for only the characters for which isupper or islower is true.

3.1.3. The iscntrl function

Synopsis
#include <ctype.h>

int iscntrl (int c );

Description

The iscntrl function tests for any control character.

3.1.4. The isdigit function

Synopsis
#include <ctype.h>

int isdigit (int c );

Description

The isdigit function tests for any decimal-digit character (as defined in ANSI C section 5.2.1).

3.1.5. The isgraph function

Synopsis
#include <ctype.h>

int isgraph (int c );

Description

The isgraph function tests for any printing character except space (' ').

3.1.6. The islower function

Synopsis
#include <ctype.h>

int islower (int c );

Description

The islower function tests for any character that is an lowercase letter or is one of an implementation-defined set of characters for which none of iscntrl, isdigit, ispunct or isspace is true. In the "C" locale, islower returns true only for the characters defined as lower case letters (as defined in ANSI C section 5.2.1).

3.1.7. The isprint function

Synopsis
#include <ctype.h>

int isprint (int c );

Description

The isprint function tests for any of the printing characters including space (' ').

3.1.8. The ispunct function

Synopsis
#include <ctype.h>

int ispunct (int c );

Description

The ispunct function tests for any printing character that is neither a space (' ') nor a character for which isalnum is true.

3.1.9. The isspace function

Synopsis
#include <ctype.h>

int isspace (int c );

Description

The isspace function tests for any character that is a standard white space character or is one of an implementation-defined set of characters for which isalnum is false. The standard white space characters are the following: space (' '), form feed ('\f'), new_line ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). In the "C" locale, isspace returns true only for standard white space characters.

3.1.10. The isupper function

Synopsis
#include <ctype.h>

int isupper (int c );

Description

The isupper function tests for any character that is an uppercase letter or is one of an implementation-defined set of characters for which none of iscntrl, isdigit, ispunctor isspace is true. In the "C" locale, isupper returns true only for the characters defined as upper case letters (as defined in ANSI C section 5.2.1).

3.1.11. The isxdigit function

Synopsis
#include <ctype.h>

int isxdigit (int c );

Description

The isxdigit functions tests for any hexadecimal-digit character (as defined in ANSI C section 6.1.3.2).

Notes

[1]

The current locale is always the C locale.