Encyclopedia  |   World Factbook  |   World Flags  |   Reference Tables  |   List of Lists     
   Academic Disciplines  |   Historical Timeline  |   Themed Timelines  |   Biographies  |   How-Tos     
Sponsor by The Tattoo Collection
Ctype.h
Main Page | See live article | Alphabetical index

Ctype.h

The header ctype.h in the ANSI C Standard Library for the C programming language contains declarations for character classification functions.

History

Early toolsmiths writing in C under Unix began developing idioms at a rapid rate to classify characters into different types. For example, the following test identifies a letter:

if ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z')

which gives a correct result if the character set is ASCII. Nevertheless, this idiom does not work for other character sets such as EBCDIC.

Pretty soon, programs became thick with tests such as the one above, or worse, tests almost like the one above. A programmer can write the same idiom several different ways, which slows comprehension and increases the chance for errors.

Before long, the idioms were replaced by the functions in .

The contents of

The contains prototypes for a dozen character classification functions:

All of these functions are of the form int isfunc(int); and return a nonzero number for true and zero for false.

and two character conversion functions:

These functions are of the form int tofunc(int); and return the parameter converted if the character is alphabetic, or the character unconverted if not.

The Single Unix Specification Version 3 adds functions similar to the above:

All of these functions except isdigit are locale-specific; their behavior may change if the locale changes.