ctype, isalpha, isupper, islower, isdigit, isxdigit, isalnum, isspace, ispunct, isprint, isgraph, iscntrl, or isascii Subroutines

Purpose

Classifies characters.

Library

Standard Character Library (libc.a)

Syntax

#include <ctype.h> 

int isalpha ( Character)
int Character;

int isupper (Character)
int Character;
int islower (Character)
int Character;
int isdigit (Character)
int Character;
int isxdigit (Character)
int Character;
int isalnum (Character)
int Character;
int isspace (Character)
int Character;
int ispunct (Character)
int Character;
int isprint (Character)
int Character;
int isgraph (Character)
int Character;
int iscntrl (Character)
int Character;
int isascii (Character)
int Character;

Description

The ctype subroutines classify character-coded integer values specified in a table. Each of these subroutines returns a nonzero value for True and 0 for False.

Note: The ctype subroutines should only be used on character data that can be represented by a single byte value ( 0 through 255 ). Attempting to use the ctype subroutines on multi-byte locale data may give inconsistent results. Wide character classification routines (such as iswprint, iswlower, etc.) should be used with dealing with multi-byte character data.

Locale Dependent Character Tests

The following subroutines return nonzero (True) based upon the character class definitions for the current locale.

Item Description
isalnum Returns nonzero for any character for which the isalpha or isdigit subroutine would return nonzero. The isalnum subroutine tests whether the character is of the alpha or digit class.
isalpha Returns nonzero for any character for which the isupper or islower subroutines would return nonzero. The isalpha subroutine also returns nonzero for any character defined as an alphabetic character in the current locale, or for a character for which none of the iscntrl, isdigit, ispunct, or isspace subroutines would return nonzero. The isalpha subroutine tests whether the character is of the alpha class.
isupper Returns nonzero for any uppercase letter [A through Z]. The isupper subroutine also returns nonzero for any character defined to be uppercase in the current locale. The isupper subroutine tests whether the character is of the upper class.
islower Returns nonzero for any lowercase letter [a through z]. The islower subroutine also returns nonzero for any character defined to be lowercase in the current locale. The islower subroutine tests whether the character is of the lower class.
isspace Returns nonzero for any white-space character (space, form feed, new line, carriage return, horizontal tab or vertical tab). The isspace subroutine tests whether the character is of the space class.
ispunct Returns nonzero for any character for which the isprint subroutine returns nonzero, except the space character and any character for which the isalnum subroutine would return nonzero. The ispunct subroutine also returns nonzero for any locale-defined character specified as a punctuation character. The ispunct subroutine tests whether the character is of the punct class.
isprint Returns nonzero for any printing character. Returns nonzero for any locale-defined character that is designated a printing character. This routine tests whether the character is of the print class.
isgraph Returns nonzero for any character for which the isprint character returns nonzero, except the space character. The isgraph subroutine tests whether the character is of the graph class.
iscntrl Returns nonzero for any character for which the isprint subroutine returns a value of False (0) and any character that is designated a control character in the current locale. For the C locale, control characters are the ASCII delete character (0127 or 0x7F), or an ordinary control character (less than 040 or 0x20). The iscntrl subroutine tests whether the character is of the cntrl class.

Locale Independent Character Tests

The following subroutines return nonzero for the same characters, regardless of the locale:

Item Description
isdigit Character is a digit in the range [0 through 9].
isxdigit Character is a hexadecimal digit in the range [0 through 9], [A through F], or [a through f].
isascii Character is an ASCII character with a value in the range [0 through 0x7F].

Parameter

Item Description
Character Indicates the character to be tested (integer value).

Return Codes

The ctype subroutines return nonzero (True) if the character specified by the Character parameter is a member of the selected character class; otherwise, a 0 (False) is returned.