• No results found

Character handling <ctype.h>

In document Programming languages — C (Page 193-198)

1 The header <ctype.h> declares several functions useful for classifying and mapping characters.172) In all cases the argument is an int, the value of which shall be representable as anunsigned char or shall equal the value of the macro EOF. 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.173) All letters and digits are printing characters.

Forward references: EOF(7.19.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 argumentcconforms 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

172) See ‘‘future library directions’’ (7.26.2).

173) 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).

none of iscntrl, isdigit,ispunct, or isspace is true.174) 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 which isspace is 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.

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);

174) The functions islower and isupper test true or false separately for each of these additional characters; all four combinations are possible.

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 The islower function tests for any character that is a lowercase letter or is one of a locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or isspace is true. In the "C" locale, islower returns 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, ispunct returns true for every printing character for which neither isspace norisalnumis 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 which isalnum is 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 The isupper function tests for any character that is an uppercase letter or is one of a locale-specific set of characters for which none of iscntrl, isdigit, ispunct, or isspace is true. In the "C" locale, isupper returns 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 which isupper is 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 giv en 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 which islower is 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 giv en locale); otherwise, the argument is returned unchanged.

In document Programming languages — C (Page 193-198)