@Go to the ‰ŠP�”›first@�”˜, ‰ŠP�”›previous@�”˜, ‰ŠP�”›next@�”˜, ‰ŠP�”›last@�”˜ section, ‰ŠP�”›table of contents@�”˜.
Œ

ˆ‰SEC54Št�”›Character Handling

@�”˜Programs that work with characters and strings often need to classify a character--is it alphabetic, is it a digit, is it whitespace, and so on--and perform case conversion operations on characters. The functions in the header file H`ctype.h'@ are provided for this purpose. ‰IDX301Š
@�”˜Since the choice of locale and character set can alter the classifications of particular character codes, all of these functions are affected by the current locale. (More precisely, they are affected by the locale currently selected for character classification--the HLC_CTYPE@ category; see section ‰ŠP�”›Categories of Activities that Locales Affect@�”˜.)
ˆ‰SEC55Št�”›Classification of Characters

‰IDX302Š‰IDX303Š‰IDX304Š‰IDX305Š
@�”˜This section explains the library functions for classifying characters. For example, Hisalpha@ is the function to test for an alphabetic character. It takes one argument, the character to test, and returns a nonzero integer if the character is alphabetic, and zero otherwise. You would use it like this: if (isalpha (c))
printf ("The character `%c' is alphabetic.\n", c);
Each of the functions in this section tests for membership in a particular class of characters; each has a name starting with H`is'@. Each of them takes one argument, which is a character to test, and returns an Hint@ which is treated as a boolean value. The character argument is passed as an Hint@, and it may be the constant value HEOF@ instead of a real character.
The attributes of any given character can vary between locales. See section ‰ŠP�”›Locales and Internationalization@�”˜, for more information on locales.
These functions are declared in the header file H`ctype.h'@. ‰IDX306Š
‰IDX307Š
A�”˜Function:@ int Dislower@ B(int Bc@)
Â‰IDX308Š@�”˜Returns true if Bc@ is a lower-case letter.À

‰IDX309Š
A�”˜Function:@ int Disupper@ B(int Bc@)
Â‰IDX310Š@�”˜Returns true if Bc@ is an upper-case letter.À

‰IDX311Š
A�”˜Function:@ int Disalpha@ B(int Bc@)
Â‰IDX312Š@�”˜Returns true if Bc@ is an alphabetic character (a letter). If Hislower@ or Hisupper@ is true of a character, then Hisalpha@ is also true.
In some locales, there may be additional characters for which Hisalpha@ is true--letters which are neither upper case nor lower case. But in the standard H"C"@ locale, there are no such additional characters.À

‰IDX313Š‰IDX314Š
A�”˜Function:@ int Disdigit@ B(int Bc@)
Â‰IDX315Š@�”˜Returns true if Bc@ is a decimal digit (H`0'@ through H`9'@).À

‰IDX316Š
A�”˜Function:@ int Disalnum@ B(int Bc@)
Â‰IDX317Š@�”˜Returns true if Bc@ is an alphanumeric character (a letter or number); in other words, if either Hisalpha@ or Hisdigit@ is true of a character, then Hisalnum@ is also true.À

‰IDX318Š
A�”˜Function:@ int Disxdigit@ B(int Bc@)
Â‰IDX319Š@�”˜Returns true if Bc@ is a hexadecimal digit. Hexadecimal digits include the normal decimal digits H`0'@ through H`9'@ and the letters H`A'@ through H`F'@ and H`a'@ through H`f'@.À

‰IDX320Š
A�”˜Function:@ int Dispunct@ B(int Bc@)
Â‰IDX321Š@�”˜Returns true if Bc@ is a punctuation character. This means any printing character that is not alphanumeric or a space character.À

‰IDX322Š
A�”˜Function:@ int Disspace@ B(int Bc@)
Â‰IDX323Š@�”˜Returns true if Bc@ is a Bwhitespace@ character. In the standard H"C"@ locale, Hisspace@ returns true for only the standard whitespace characters:
H' '
Ä@space
ÂH'\f'
Ä@formfeed
ÂH'\n'
Ä@newline
ÂH'\r'
Ä@carriage return
ÂH'\t'
Ä@horizontal tab
ÂH'\v'
Ä@vertical tabÂ
À

‰IDX324Š
A�”˜Function:@ int Disblank@ B(int Bc@)
Â‰IDX325Š@�”˜Returns true if Bc@ is a blank character; that is, a space or a tab. This function is a GNU extension.À

‰IDX326Š
A�”˜Function:@ int Disgraph@ B(int Bc@)
Â‰IDX327Š@�”˜Returns true if Bc@ is a graphic character; that is, a character that has a glyph associated with it. The whitespace characters are not considered graphic.À

‰IDX328Š
A�”˜Function:@ int Disprint@ B(int Bc@)
Â‰IDX329Š@�”˜Returns true if Bc@ is a printing character. Printing characters include all the graphic characters, plus the space (H` '@) character.À

‰IDX330Š
A�”˜Function:@ int Discntrl@ B(int Bc@)
Â‰IDX331Š@�”˜Returns true if Bc@ is a control character (that is, a character that is not a printing character).À

‰IDX332Š
A�”˜Function:@ int Disascii@ B(int Bc@)
Â‰IDX333Š@�”˜Returns true if Bc@ is a 7-bit Hunsigned char@ value that fits into the US/UK ASCII character set. This function is a BSD extension and is also an SVID extension.À

ˆ‰SEC56Št�”›Case Conversion

‰IDX334Š‰IDX335Š‰IDX336Š
@�”˜This section explains the library functions for performing conversions such as case mappings on characters. For example, Htoupper@ converts any character to upper case if possible. If the character can't be converted, Htoupper@ returns it unchanged.
These functions take one argument of type Hint@, which is the character to convert, and return the converted character as an Hint@. If the conversion is not applicable to the argument given, the argument is returned unchanged.
DCompatibility Note:@ In pre-ISO C dialects, instead of returning the argument unchanged, these functions may fail when the argument is not suitable for the conversion. Thus for portability, you may need to write Hislower(c) ? toupper(c) : c@ rather than just Htoupper(c)@.
These functions are declared in the header file H`ctype.h'@. ‰IDX337Š

A�”˜Function:@ int Dtolower@ B(int Bc@)
Â‰IDX338Š@�”˜If Bc@ is an upper-case letter, Htolower@ returns the corresponding lower-case letter. If Bc@ is not an upper-case letter, Bc@ is returned unchanged.À

AFunction:@ int Dtoupper@ B(int Bc@)
Â‰IDX339Š@�”˜If Bc@ is a lower-case letter, Htolower@ returns the corresponding upper-case letter. Otherwise Bc@ is returned unchanged.À

AFunction:@ int Dtoascii@ B(int Bc@)
Â‰IDX340Š@�”˜This function converts Bc@ to a 7-bit Hunsigned char@ value that fits into the US/UK ASCII character set, by clearing the high-order bits. This function is a BSD extension and is also an SVID extension.À

AFunction:@ int D_tolower@ B(int Bc@)
Â‰IDX341Š@�”˜This is identical to Htolower@, and is provided for compatibility with the SVID. See section ‰ŠP�”›SVID (The System V Interface Description)@�”˜.À

AFunction:@ int D_toupper@ B(int Bc@)
Â‰IDX342Š@�”˜This is identical to Htoupper@, and is provided for compatibility with the SVID.À

Œ
Go to the ‰ŠP�”›first@�”˜, ‰ŠP�”›previous@�”˜, ‰ŠP�”›next@�”˜, ‰ŠP�”›last@�”˜ section, ‰ŠP�”›table of contents@�”˜.