【C语法学习】28 - 字符测试函数

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.

11 isprint()函数

isprint()函数检测ch是否是可打印的,函数原型如下:

int isprint(int ch);

C语言标准描述如下:

1. Checks if the given character can be printed, i.e. it is either a number (0123456789), an uppercase letter (ABCDEFGHIJKLMNOPQRSTUVWXYZ), a lowercase letter (abcdefghijklmnopqrstuvwxyz), a punctuation character(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~), or space, or any character classified as printable by 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 can be printed, zero otherwise.

12 ispunct()函数

ispunct()函数检测ch是否是标点符号,函数原型如下:

int ispunct(int ch);

C语言标准描述如下:

1. Checks if the given character is a punctuation character in the current C locale. The default C locale classifies the characters !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ as punctuation.
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 punctuation character, zero otherwise.

13 tolower()函数

tolower()函数将大写字符转换为小写字母,函数原型如下:

int tolower( int ch );

C语言标准描述如下:

1. Converts the given character to lowercase according to the character conversion rules defined by the currently installed C locale.
2. In the default "C" locale, the following uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ are replaced with respective lowercase letters abcdefghijklmnopqrstuvwxyz.
3. Lowercase version of ch or unmodified ch if no lowercase version is listed in the current C locale.

14 toupper()函数

toupper()函数将小写字符转换为大写字母,函数原型如下:

int toupper( int ch );

C语言标准描述如下:

1. Converts the given character to lowercase according to the character conversion rules defined by the currently installed C locale.
2. In the default "C" locale, the following uppercase letters ABCDEFGHIJKLMNOPQRSTUVWXYZ are replaced with respective lowercase letters abcdefghijklmnopqrstuvwxyz.
3. Uppercase version of ch or unmodified ch if no uppercase version is listed in the current C locale.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值