liveBook · Manning

Character classifier

As explained in Modern C, Third Edition

A character classifier function is a C library interface that tests whether a character belongs to a specified character class.

A character classifier is a function or macro from <ctype.h> that tests whether an int argument belongs to a character class. The interface includes isalpha, isdigit, isspace, isupper, islower, ispunct, and related classifiers; each accepts and returns int for historical reasons. section 8.5

Classifying digits before conversion

Use isdigit(a) before converting a decimal character with a - '0'. Decimal digits are consecutive, and isdigit is not locale-dependent. Other classifiers, such as isupper, can guide subsequent processing.

How Modern C, Third Edition covers it

How deep it goes
Defines the classifier family, int-based interface, class meanings, and locale extensions without detailing implementation internals.
Examples
Uses decimal, hexadecimal, alphabetic, uppercase, whitespace, punctuation, control, graphical, and printable character classes.
What it assumes
Assumes familiarity with C character constants, strings, and integer types while clarifying why classifiers use int.
What you can do after
Apply it via <ctype.h> to test character classes and branch safely in conversion routines.
How it connects
Connects character classification with character encoding, locales, string processing, and character conversion.

Also explained in

Compare how 2 books explain character classifier →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.