Wednesday, August 31, 2016

C Library Header– ctype

This header contains character handling functions. It declares a set of functions to classify and transform individual characters. The ctype header is used for testing and converting characters.

There are two sets of functions:
Character classification functions – is function: They check whether the character passed as parameter belongs to a certain category. The is... functions test the given character and return a nonzero (true) result if it satisfies the following conditions. If not, then 0 (false) is returned. Conditions:
isalnum a letter (A to Z or a to z) or a digit (0 to 9)
isalpha a letter (A to Z or a to z)
iscntrl any control character (0x00 to 0x1F or 0x7F)
isdigit a digit (0 to 9)
isgraph any printing character except for the space character (0x21 to 0x7E)
islower a lowercase letter (a to z)
isprint any printing character (0x20 to 0x7E)
ispunct any punctuation character (any printing character except for space character or isalnum)
isspace a whitespace character (space, tab, carriage return, new line, vertical tab, or formfeed)
isupper an uppercase letter (A to Z)
isxdigit a hexadecimal digit (0 to 9, A to F, or a to f)

Character conversion functions – to function: Two functions that convert between letter cases. The to... functions provide a means to convert a single character. If the character matches the appropriate condition, then it is converted. Otherwise the character is returned unchanged.
tolowerIf the character is an uppercase character (A to Z), then it is converted to lowercase (a to z)
toupperIf the character is a lowercase character (a to z), then it is converted to uppercase (A to Z)

The <ctype.h> header shall define the following functions:
isalnum Check if character is alphanumeric
isalpha Check if character is alphabetic
Isblank Check if character is blank (C11)
iscntrl Check if character is a control character
isdigit Check if character is decimal digit
isgraph Check if character has graphical representation
islower Check if character is lowercase letter
isprint Check if character is printable
ispunct Check if character is a punctuation character
isspace Check if character is a white-space
isupper Check if character is uppercase letter
isxdigit Check if character is hexadecimal digit
tolower Convert uppercase letter to lowercase
toupper Convert lowercase letter to uppercase

Related topics:
<assert.h>   |   <complex.h>   |   <errno.h>   |   <fenv.h>   |   <float.h>   |   Standard Library in C

List of topics: C Programming

No comments:

Post a Comment