c语言检查字符函数
When working in C, we can use the ctype.h
standard library set of functions to check the value of a char
type variable.
在C语言中工作时,我们可以使用ctype.h
标准库函数集来检查char
类型变量的值。
We have access to several useful checks:
我们可以访问一些有用的检查:
isalnum()
checks if a character is alphanumericisalnum()
检查字符是否为字母数字isalpha()
checks if a character is alphabeticisalpha()
检查字符是否为字母iscntrl()
checks if a character is a control characteriscntrl()
检查字符是否为控制字符isdigit()
checks if a character is a digitisdigit()
检查字符是否为数字isgraph()
checks if a character is a printable ASCII character (but not a space)isgraph()
检查字符是否为可打印的ASCII字符 (但不能为空格)islower()
checks if a character is lowercaseislower()
检查字符是否为小写isprint()
checks if a character is a printable ASCII characterisprint()
检查字符是否为可打印的ASCII字符ispunct()
checks if a character is a punctuation character (a printable char, not a space, not alphanumeric)ispunct()
检查字符是否为标点符号(可打印字符,而不是空格,不是字母数字)isspace()
checks if a character is a whitespace character (see more later)isspace()
检查字符是否为空格字符(请参阅稍后)isupper()
checks if a character is uppercaseisupper()
检查字符是否为大写isxdigit()
checks if a character is an hexadecimal digit (0
-F
)isxdigit()
检查字符是否为十六进制数字(0
-F
)
I mentioned that isspace()
checks if a character is a whitespace character. What is a whitespace character?
我提到过isspace()
检查字符是否为空白字符。 什么是空白字符?
Horizontal tab (HT),
'\t'
, character 9 of the ASCII table水平制表符(HT),
'\t'
,ASCII表的字符9Vertical tab (VT),
'\v'
, character 11 of the ASCII table垂直制表符(VT),
'\v'
,ASCII表的字符11Form Feed (FF),
'\f'
, character 12 of the ASCII table换页(FF),
'\f'
,ASCII表的字符12Carriage Return (CR),
'\r'
, character 13 of the ASCII table回车符(CR),
'\r'
,ASCII表的字符13Space,
' '
, character 32 of the ASCII tableASCII表的空格
' '
,字符32New line,
'\n'
换行
'\n'
c语言检查字符函数