【C语法学习】28 - 字符测试函数
文章目录
- 1 isalnum()函数
- 2 isalpha()函数
- 3 islower()函数
- 4 isupper()函数
- 5 isdigit()函数
- 6 isxdigit()函数
- 7 iscntrl()函数
- 8 isgraph()函数
- 9 isspace()函数
- 10 isblank()函数
- 11 isprintf()函数
1 isalnum()函数
isalnum()函数检测ch是否是字母和数字,函数原型如下:
int isalnum(int ch);
C语言标准描述如下:
1. Checks if the given character is an alphanumeric character as classified by the current C locale. In the default locale, the following characters are alphanumeric:(1) digits (0123456789)(2) uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ)(3) lowercase letters (abcdefghijklmnopqrstuvwxyz)
2. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
3. Non-zero value if the character is an alphanumeric character, 0 otherwise.
2 isalpha()函数
isalpha()函数检测ch是否是字母,函数原型如下:
int isalpha(int ch);
C语言标准描述如下:
1. Checks if the given character is an alphabetic character, i.e. either an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), or a lowercase letter (abcdefghijklmnopqrstuvwxyz).
2. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
3. Non-zero value if the character is an alphabetic character, zero otherwise.
3 islower()函数
islower()函数检测ch是否为小写字母,函数原型如下:
int islower(int ch);
C语言标准描述如下:
1. Checks if the given character is classified as a lowercase character according to the current C locale. In the default "C" locale, islower returns true only for the lowercase letters (abcdefghijklmnopqrstuvwxyz).
2. If islower returns true, it is guaranteed that iscntrl, isdigit, ispunct, and isspace return false for the same character in the same C locale.
3. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
4. Non-zero value if the character is a lowercase letter, zero otherwise.
4 isupper()函数
isupper()函数检测ch是否为大写字母,函数原型如下:
int isupper(int ch);
C语言标准描述如下:
1. Checks if the given character is an uppercase character according to the current C locale. In the default "C" locale, isupper returns true only for the uppercase letters (ABCDEFGHIJKLMNOPQRSTUVWXYZ).
2. If isupper returns true, it is guaranteed that iscntrl, isdigit, ispunct, and isspace return false for the same character in the same C locale.
3. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
4. Non-zero value if the character is an uppercase letter, zero otherwise.
5 isdigit()函数
isdigit()函数检测ch是否为十进制数字,函数原型如下:
int isdigit(int ch);
C语言标准描述如下:
1. Checks if the given character is a numeric character (0123456789).
2. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
3. Non-zero value if the character is a numeric character, zero otherwise.
6 isxdigit()函数
isxdigit()函数检测ch是否为十六进制数字,函数原型如下:
int isxdigit(int ch);
C语言标准描述如下:
1. Checks if the given character is a hexadecimal numeric character (0123456789abcdefABCDEF) or is classified as a hexadecimal character.
2. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
3. Non-zero value if the character is an hexadecimal numeric character, zero otherwise.
7 iscntrl()函数
iscntrl()函数检测ch是否为控制字符,函数原型如下:
int iscntrl(int ch);
C语言标准描述如下:
1. Checks if the given character is a control character, i.e. codes 0x00-0x1F and 0x7F.
2. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
3. Non-zero value if the character is a control character, zero otherwise.
8 isgraph()函数
isgraph()函数检测ch是否有图形表示,函数原型如下:
int isgraph(int ch);
C语言标准描述如下:
1. Checks if the given character has a graphical representation, i.e. it is either a number (0123456789), an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), a lowercase letter (abcdefghijklmnopqrstuvwxyz), or a punctuation character (!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~), or any graphical character specific to the current C locale.
2. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
3. Non-zero value if the character has a graphical representation character, zero otherwise.
9 isspace()函数
isspace()函数检测ch是否是空白字符,函数原型如下:
int isspace(int ch);
C语言标准描述如下:
1. Checks if the given character is either(1) A standard white-space character:(2) Space (0x20, ' '),(3) Form feed (0x0c, '\f'),(4) Line feed (0x0a, '\n'),(5) Carriage return (0x0d, '\r'),(6) Horizontal tab (0x09, '\t'),(7) Vertical tab (0x0b, '\v'),(8) Or a locale-specific white-space character.
2. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
3. Non-zero value if the character is a whitespace character, zero otherwise.
10 isblank()函数
isblank()函数检测ch是否为空白字符,函数原型如下:
int isblank(int ch);
C语言标准描述如下:
1. Checks if the given character is a blank character in the current C locale. In the default C locale, only space (0x20) and horizontal tab (0x09) are classified as blank.
2. The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.
3. Non-zero value if the character is a blank character, zero otherwise.