• No results found

FE_DEC_DOWNWARD FE_DEC_TONEAREST FE_DEC_TONEARESTFROMZERO FE_DEC_TOWARDZERO FE_DEC_UPWARD FE_DEC_DYNAMIC

7.4 Character handling <ctype.h>

1 The header<ctype.h>declares several functions useful for classifying and mapping characters.214) In all cases the argument is anint, the value of which shall be representable as anunsigned char or shall equal the value of the macroEOF. If the argument has any other value, the behavior is undefined.

2 The behavior of these functions is affected by the current locale. Those functions that have locale-specific aspects only when not in the"C"locale are noted below.

3 The term printing character refers to a member of a locale-specific set of characters, each of which occupies one printing position on a display device; the term control character refers to a member of a locale-specific set of characters that are not printing characters.215) All letters and digits are printing characters.

Forward references: EOF(7.21.1), localization (7.11).

7.4.1 Character classification functions

1 The functions in this subclause return nonzero (true) if and only if the value of the argumentc conforms to that in the description of the function.

7.4.1.1 Theisalnumfunction Synopsis

1 #include <ctype.h>

int isalnum(int c);

Description

2 Theisalnumfunction tests for any character for whichisalphaorisdigitis true.

7.4.1.2 Theisalphafunction Synopsis

1 #include <ctype.h>

int isalpha(int c);

Description

2 Theisalphafunction tests for any character for whichisupperorisloweris true, or any character that is one of a locale-specific set of alphabetic characters for which none ofiscntrl,isdigit, ispunct, orisspaceis true.216) In the"C"locale,isalphareturns true only for the characters for whichisupperorisloweris true.

7.4.1.3 Theisblankfunction Synopsis

1 #include <ctype.h>

int isblank(int c);

Description

2 Theisblankfunction tests for any character that is a standard blank character or is one of a locale-specific set of characters for whichisspaceis true and that is used to separate words within a line of text. The standard blank characters are the following: space (’ ’), and horizontal tab (’\t’). In the"C"locale,isblankreturns true only for the standard blank characters.

214)See "future library directions" (7.31.2).

215)In an implementation that uses the seven-bit US ASCII character set, the printing characters are those whose values lie from 0x20 (space) through 0x7E (tilde); the control characters are those whose values lie from 0 (NUL) through 0x1F (US), and the character 0x7F (DEL).

216)The functionsislowerandisuppertest true or false separately for each of these additional characters; all four combina-tions are possible.

7.4.1.4 Theiscntrlfunction Synopsis

1 #include <ctype.h>

int iscntrl(int c);

Description

2 Theiscntrlfunction tests for any control character.

7.4.1.5 Theisdigitfunction Synopsis

1 #include <ctype.h>

int isdigit(int c);

Description

2 Theisdigitfunction tests for any decimal-digit character (as defined in 5.2.1).

7.4.1.6 Theisgraphfunction Synopsis

1 #include <ctype.h>

int isgraph(int c);

Description

2 Theisgraphfunction tests for any printing character except space (’ ’).

7.4.1.7 Theislowerfunction Synopsis

1 #include <ctype.h>

int islower(int c);

Description

2 Theislowerfunction tests for any character that is a lowercase letter or is one of a locale-specific set of characters for which none ofiscntrl,isdigit,ispunct, orisspaceis true. In the"C"locale, islowerreturns true only for the lowercase letters (as defined in 5.2.1).

7.4.1.8 Theisprintfunction Synopsis

1 #include <ctype.h>

int isprint(int c);

Description

2 Theisprintfunction tests for any printing character including space (’ ’).

7.4.1.9 Theispunctfunction Synopsis

1 #include <ctype.h>

int ispunct(int c);

Description

2 Theispunctfunction tests for any printing character that is one of a locale-specific set of punctuation characters for which neitherisspacenorisalnumis true. In the"C"locale,ispunctreturns true for every printing character for which neitherisspacenorisalnumis true.

7.4.1.10 Theisspacefunction Synopsis

1 #include <ctype.h>

int isspace(int c);

Description

2 Theisspacefunction tests for any character that is a standard white-space character or is one of a locale-specific set of characters for whichisalnumis false. The standard white-space characters are the following: space (’ ’), form feed (’\f’), new-line (’\n’), carriage return (’\r’), horizontal tab (’\t’), and vertical tab (’\v’). In the"C"locale,isspacereturns true only for the standard white-space characters.

7.4.1.11 Theisupperfunction Synopsis

1 #include <ctype.h>

int isupper(int c);

Description

2 Theisupperfunction tests for any character that is an uppercase letter or is one of a locale-specific set of characters for which none ofiscntrl,isdigit,ispunct, orisspaceis true. In the"C"locale, isupperreturns true only for the uppercase letters (as defined in 5.2.1).

7.4.1.12 Theisxdigitfunction Synopsis

1 #include <ctype.h>

int isxdigit(int c);

Description

2 Theisxdigitfunction tests for any hexadecimal-digit character (as defined in 6.4.4.1).

7.4.2 Character case mapping functions

7.4.2.1 Thetolowerfunction Synopsis

1 #include <ctype.h>

int tolower(int c);

Description

2 Thetolowerfunction converts an uppercase letter to a corresponding lowercase letter.

Returns

3 If the argument is a character for whichisupperis true and there are one or more corresponding characters, as specified by the current locale, for whichisloweris true, thetolowerfunction returns one of the corresponding characters (always the same one for any given locale); otherwise, the argument is returned unchanged.

7.4.2.2 Thetoupperfunction Synopsis

1 #include <ctype.h>

int toupper(int c);

Description

2 Thetoupperfunction converts a lowercase letter to a corresponding uppercase letter.

Returns

3 If the argument is a character for whichisloweris true and there are one or more corresponding characters, as specified by the current locale, for whichisupperis true, thetoupperfunction returns one of the corresponding characters (always the same one for any given locale); otherwise, the argument is returned unchanged.