ANSI C文档(C89 http://flash-gordon.me.uk/ansi.c.txt)如是说:
4.3 CHARACTER HANDLING <ctype.h>
The header <ctype.h> declares several functions useful for testingand mapping characters./89/ In all cases the argument is an int , the value of which shall be representable as an unsigned char or shallequal the value of the macro EOF . If the argument has any othervalue, the behavior is undefined.
这里说明了ctype.h里面实现的所有测试字符的函数传进去的参数都以int形参给出,并且有效值是无符号字符(unsigned char)或EOF宏(通常实现为-1),其他输入的int型值行为未定义。
C标准库规定了需要实现的13个字符处理函数,可以分为两类——字符测试函数和字符转换函数。
下面给出了C99的字符测试函数表,表中是12个字符测试函数,比原来的标准多出来一个isblank。http://www.open-std.org/JTC1/SC22/WG14/www/docs/C99RationaleV5.10.pdf P118
7.4.1.3 The isblank function
A new feature of C99: text processing applications often need to distinguish white space that can 15 occur within lines from white space that separates lines (for example, see §6.10 regarding use of whitespace in the preprocessor). This distinction is also a property of POSIX locale definition files.
ASCII values | characters | iscntrl | isblank | isspace | isupper | islower | isalpha | isdigit | isxdigit | isalnum | ispunct | isgraph | isprint |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0x00 .. 0x08 | NUL, (other control codes) | x | |||||||||||
0x09 | tab ('\t') | x | x | x | |||||||||
0x0A .. 0x0D | (white-space control codes: '\f','\v','\n','\r') | x | x | ||||||||||
0x0E .. 0x1F | (other control codes) | x | |||||||||||
0x20 | space (' ') | x | x | x | |||||||||
0x21 .. 0x2F | !"#$%&'()*+,-./ | x | x | x | |||||||||
0x30 .. 0x39 | 0123456789 | x | x | x | x | x | |||||||
0x3a .. 0x40 | :;<=>?@ | x | x | x | |||||||||
0x41 .. 0x46 | ABCDEF | x | x | x | x | x | x | ||||||
0x47 .. 0x5A | GHIJKLMNOPQRSTUVWXYZ | x | x | x | x | x | |||||||
0x5B .. 0x60 | [\]^_` | x | x | x | |||||||||
0x61 .. 0x66 | abcdef | x | x | x | x | x | x | ||||||
0x67 .. 0x7A | ghijklmnopqrstuvwxyz | x | x | x | x | x | |||||||
0x7B .. 0x7E | {|}~ | x | x | x | |||||||||
0x7F | (DEL) | x |
上表来源:http://www.cplusplus.com/reference/cctype/
下面英文部分是字符测试函数要求描述,摘自C89标准文档说明
4.3.1 Character testing functions
The functions in this section return nonzero (true) if and only ifthe value of the argument c conforms to that in the description of thefunction.
4.3.1.1 The isalnum functionSynopsis
#include <ctype.h>
int isalnum(int c);
Description The isalnum function tests for any character for which isalpha orisdigit is true.
4.3.1.2 The isalpha functionSynopsis
#include <ctype.h>
int isalpha(int c);
Description The isalpha function tests for any character for which isupper orislower is true, or any of an implementation-defined set of charactersfor which none of iscntrl , isdigit , ispunct , or isspace is true.In the C locale, isalpha returns true only for the characters forwhich isupper or islower is true.
4.3.1.3 The iscntrl functionSynopsis
#include <ctype.h>
int iscntrl(int c);
Description The iscntrl function tests for any control character.
4.3.1.4 The isdigit functionSynopsis
#include <ctype.h>
int isdigit(int c);
Description The isdigit function tests for any decimal-digit character (asdefined in $2.2.1).
4.3.1.5 The isgraph functionSynopsis
#include <ctype.h>
int isgraph(int c);
Description The isgraph function tests for any printing character except space (' ').
4.3.1.6 The islower functionSynopsis
#include <ctype.h>
int islower(int c);Description
The islower function tests for any lower-case letter or any of animplementation-defined set of characters for which none of iscntrl ,isdigit , ispunct , or isspace is true. In the C locale, islowerreturns true only for the characters defined as lower-case