<ctype.h>
Early toolsmiths writing in C under Unix began developing idioms at a rapid rate to classify characters into different types. For example, in the ASCII character set, the following test identifies a letter:if ('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z')
However, this idiom does not necessarily 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.
The <ctype.h> contains prototypes for a dozen character classification functions. All of these functions except isdigit and isxdigit are locale-specific; their behavior may change if the locale changes.[clarification needed]
isalnum test for alphanumeric character
isalpha test for alphabetic character
isblank test for blank character (new in C99)
iscntrl test for control character
isdigit test for digit. Not locale-specific.
isgraph test for graphic character, excluding the space character.
islower test for lowercase character
isprint test for printable character, including the space character.
ispunct test for punctuation character
isspace test for any whitespace character
isupper test for uppercase character
isxdigit test for hexadecimal digit. Not locale-specific.
Return the converted character unless it is not alphabetic.
tolower convert character to lowercase
toupper convert character to uppercase
0 comments:
Post a Comment