COHERENT manpages
This page displays the COHERENT manpage for ctype.h [Header file for data tests].
List of available manpages
Index
ctype.h -- Header File Header file for data tests #include <ctype.h> ctype.h declares and defines the following routines, which can check and transform character types: _tolower()Convert an upper-case character to lower case _toupper()Convert a lower-case character to upper case isalnum() Test if alphanumeric character isalpha() Test if alphabetic character isascii() Test if ASCII character iscntrl() Test if a control character isdigit() Test if a numeric digit isgraph() Test if a graphics character islower() Test if lower-case character isprint() Test if printable character ispunct() Test if punctuation mark isspace() Test if a tab, space, or return isupper() Test if upper-case character isxdigit()Test if hexadecimal numeral toascii() Convert a character to ASCII tolower() Convert an upper-case character to lower case toupper() Convert a lower-case character to upper case Example The following example demonstrates isalnum(), isalpha(), isascii(), iscntrl(), isdigit(), islower(), isprint(), ispunct(), and isspace(). It prints information about the type of characters it contains. #include <ctype.h> #include <stdio.h> main() { FILE *fp; char fname[20]; int ch; int alnum = 0; int alpha = 0; int allow = 0; int control = 0; int printable = 0; int punctuation = 0; int space = 0; printf("Enter name of text file to examine: "); fflush(stdout); gets(fname); if ((fp = fopen(fname, "r")) != NULL) { while ((ch = fgetc(fp)) != EOF) { if (isascii(ch)) { if (isalnum(ch)) alnum++; if (isalpha(ch)) alpha++; if (islower(ch)) allow++; if (iscntrl(ch)) control++; if (isprint(ch)) printable++; if (ispunct(ch)) punctuation++; if (isspace(ch)) space++; } else { printf("%s is not ASCII.\n", fname); exit(1); } } printf("%s has the following:\n", fname); printf("%d alphanumeric characters\n", alnum); printf("%d alphabetic characters\n", alpha); printf("%d alphabetic lower-case characters\n", allow); printf("%d control characters\n", control); printf("%d printable characters\n", printable); printf("%d punctuation marks\n", punctuation); printf("%d white space characters\n", space); exit(0); } else { printf("Cannot open \"%s\".\n", fname); exit(2); } } See Also header files, libc ANSI Standard, §7.3 Notes The argument for a ctype function or macro should be an int that is representable as an unsigned char or EOF -- i.e., [-1, 0, ..., 255], as described in the ANSI standard §4.3. The functions _tolower(), _toupper(), isascii(), and toascii() are not part of the ANSI standard. Programs that use them may not be portable to all implementations of C.