ctype.h
isxxxx Functions
- Header
- ctype.h
- Prototype
- int isalnum(int c);
int isalpha(int c);
int __isascii(int c);
int iscntrl(int c);
int __iscsym(int c);
int __iscsymf(int c);
int isdigit(int c);
int isgraph(int c);
int islower(int c);
int isprint(int c);
int ispunct(int c);
int isspace(int c);
int isupper(int c);
int isxdigit(int c); - Description
- These macros, implemented as functions, test an integer value of a character (c) and return a non-zero value if the integer satisfies the test condition. If the integer does not satisfy the condition, these functions return 0. The ASCII character set is assumed. Only values of c between -1 and 255 are valid, except for __isascii, which is valid for any int. To invoke the function, undefine the macro name.
- Synonym
- Macros isascii, iscsym, iscsymf
- Return Value
- The return values are listed in the following table:
Function Returns non-zero if c is ... isalnum a letter or a digit. isalpha a letter. __isascii between 0 and 127. iscntrl a control character (0 to 0x1F), or c == 0x7F. __iscsym a letter, underscore or digit. __iscsymf a letter or underscore. isdigit the digits 0 to 9. isgraph a printing character (excluding the space). islower a lower-case character. isprint a printing character (including the space). ispunct a punctuation character. isspace a tab, linefeed, vertical tab, form feed, return, or space. isupper an upper-case character. isxdigit one of the characters 0 to 9, A to F, or a to f. - Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- Example
-
/* Example for isXXXX */ #include <ctype.h> #include <stdio.h> #include <conio.h> #include <stdlib.h> void main() { int test; char *ans[2] = {" not ", ""}; for (test = -1; test < 256; test++) { printf("\n\n\nThe value %02x is:\n", test); printf("%salphanumeric\n", ans[(isalnum(test) != 0)]); printf("%sa letter\n", ans[(isalpha(test) != 0)]); printf("%sascii\n", ans[(__isascii(test) != 0)]); printf("%sa control\n", ans[(iscntrl(test) != 0)]); printf("%sa letter, underscore or digit\n", ans[(__iscsym(test) != 0)]); printf("%sa letter or underscore\n", ans[(__iscsymf(test) != 0)]); printf("%sa digit\n", ans[(isdigit(test) != 0)]); printf("%sprintable/ not a space\n", ans[(isgraph(test) != 0)]); printf("%slower case\n", ans[(islower(test) != 0)]); printf("%sprintable\n", ans[(isprint(test) != 0)]); printf("%sa punctuator\n", ans[(ispunct(test) != 0)]); printf("%swhite space\n", ans[(isspace(test) != 0)]); printf("%supper case\n", ans[(isupper(test) != 0)]); printf("%sa hexadecimal digit\n", ans[(isxdigit(test) != 0)]); printf("\n* Press a key for the next value*\n"); getch(); } }
- Output
The value ffff is: not alphanumeric not a letter not ascii not a control not a letter, underscore or digit not a letter or underscore not a digit not printable/ not a space not lower case not printable not a punctuator not white space not upper case not a hexadecimal digit *Press a key for the next value* . . . The value 41 is: alphanumeric a letter ascii not a control a letter, underscore or digit a letter or underscore not a digit printable/ not a space not lower case printable not a punctuator not white space upper case a hexadecimal digit *Press a key for the next value* . . .
__toascii
- Header
- ctype.h
- Prototype
- int __toascii(int c);
- Description
- The __toascii function converts c to a character by taking any integer value and discarding all but the low order seven bits making up an ASCII character. If c is already a valid character, then it is returned unchanged. Implemented as a macro in ctype.h, __toascii is also included as a function within the library. Undefining the macros, or not including ctype.h, will cause the library functions to be used.
- Synonym
- Function: toascii
- Return Value
- Returns the low seven bits of c. There is no error return.
- Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- Example
- See _tolower
_tolower, tolower, _toupper, toupper
- Header
- ctype.h
- Prototype
- int _tolower(int c); int tolower(int c);
int _toupper(int c); int toupper(int c); - Description
- The tolower function converts any integer value c in the range of
'A' -'Z' to lowercase. The _tolower function is special version of
tolower which is intended for use only when c is uppercase. If
_tolower encounters a value that is not an uppercase letter, the
result is undefined.
toupper converts to uppercase the integer value c in the range of 'a' -'z'. Function _toupper is a special version of toupper that is intended for use only when c is lowercase. If _toupper encounters a value that is not a lowercase letter, the result is undefined.
These functions are implemented as macros in ctype.h, and are also included as functions within the library. Undefining the macros, or not including ctype.h, defaults to usage of the library functions. - Return Value
- tolower returns c, converted to lower case if it was uppercase, otherwise c is returned unchanged. toupper returns c, converted to upper case if it was lower case, otherwise c is returned unchanged. If _tolower and _toupper encounter an invalid character, the result is undefined.
- Compatibility
- DOS Windows 3.x Phar Lap DOSX Win32
- Example
-
/* Example for tolower Also demonstrates _toascii, _tolower, toupper, _toupper */ #include <stdlib.h> #include <stdio.h> #include <ctype.h> void main () { char *str = "Moral indignation is jealousy with a halo. - H. G. Wells"; char *p; printf("Original string: \"%s\"\n", str); printf("After tolower: \""); for (p = str; *p; p++) printf("%c", tolower(*p)); printf("\"\n"); printf("After toupper: \""); for (p = str; *p; p++) printf("%c", toupper(*p)); printf("\"\n"); }
- Output
Original string: "Moral indignation is jealousy with a halo. - H. G. Wells" After tolower: "moral indignation is jealousy with a halo. - h. g. wells" After toupper: "MORAL INDIGNATION IS JEALOUSY WITH A HALO. - H. G. WELLS"