![](https://csdnimg.cn/release/download_crawler_static/86647610/bg1.jpg)
Linux C 函数参考
![](https://csdnimg.cn/release/download_crawler_static/86647610/bg2.jpg)
isalnum(测试字符是否为英文或数字)
相关函数 isalpha,isdigit,islower,isupper
表头文件 #include<ctype.h>
定义函数 int isalnum (int c)
函数说明
检查参数 c 是否为英文字母或阿拉伯数字,在标准 c 中相当于使用
(isalpha( c )|| isdigit( c ))做测试。
返回值 若参数 c 为字母或数字,则返回 TRUE,否则返回 NULL( 0 )。
附加说明 此为宏定义,非真正函数。
范例
/* 找出 str 字符串中为英文字母或数字的字符 */
#include < ctype.h>
main()
{
char str[]=”123c@#FDsP[e?”;
int i;
for (i=0;str[i]!=0;i++ )
if ( isalnum(str[i])) printf(“%c is an alphanumeric character\n”,str[i]);
}
执行
1 is an apphabetic character
2 is an apphabetic character
3 is an apphabetic character
c is an apphabetic character
F is an apphabetic character
D is an apphabetic character
s is an apphabetic character
P is an apphabetic character
e is an apphabetic character
![](https://csdnimg.cn/release/download_crawler_static/86647610/bg3.jpg)
isalpha (测试字符是否为英文字母)
相关函数 isalnum,islower,isupper
表头文件 #include<ctype.h>
定义函数 int isalpha (int c)
函数说明
检查参数 c 是否为英文字母,在标准 c 中相当于使用 (isupper(c)
||islower(c))做测试。
返回值 若参数 c 为英文字母,则返回 TRUE,否则返回 NULL( 0 )。
附加说明 此为宏定义,非真正函数
范例
/* 找出 str 字符串中为英文字母的字符*/
#include <ctype.h>
main()
{
char str[]=”123c@#FDsP[e?”;
int i;
for (i=0;str[i]!=0;i++)
if(isalpha(str[i])) printf(“%c is an alphanumeric character\n”,str[i]);
}
执行
c is an apphabetic character
F is an apphabetic character
D is an apphabetic character
s is an apphabetic character
P is an apphabetic character
e is an apphabetic character
![](https://csdnimg.cn/release/download_crawler_static/86647610/bg4.jpg)
isascii(测试字符是否为 ASCII 码字符)
相关函数 iscntrl
表头文件 #include <ctype.h>
定义函数 int isascii(int c);
函数说明
检查参数 c 是否为 ASCII 码字符,也就是判断 c 的范围是否在 0 到
127 之间。
返回值 若参数 c 为 ASCII 码字符,则返回 TRUE,否则返回 NULL ( 0 )。
附加说明 此为宏定义,非真正函数。
范例
/* 判断 int i 是否具有对映的 ASCII 码字符 */
#include<ctype.h>
main()
{
int i;
for(i=125;i<130;i++)
if(isascii(i))
printf("%d is an ascii character:%c\n",i,i);
else
printf("%d is not an ascii character\n",i);
}
执行
125 is an ascii character:}
126 is an ascii character:~
127 is an ascii character:
128 is not an ascii character
129 is not an ascii character
![](https://csdnimg.cn/release/download_crawler_static/86647610/bg5.jpg)
iscntrl(测试字符是否为 ASCII 码的控制字符)
相关函数 isascii
表头文件 #include <ctype.h>
定义函数 int iscntrl(int c);
函数说明
检查参数 c 是否为 ASCII 控制码,也就是判断 c 的范围是否在 0 到
30 之间
返回值 若参数 c 为 ASCII 控制码,则返回 TRUE,否则返回 NULL(0)。
附加说明 此为宏定义,非真正函数。
isdigit(测试字符是否为阿拉伯数字)
相关函数 isxdigit
表头文件 #include<ctype.h>
定义函数 int isdigit(int c)
函数说明 检查参数 c 是否为阿拉伯数字 0 到 9。
返回值 若参数 c 为阿拉伯数字,则返回 TRUE,否则返回 NULL(0)。
附加说明 此为宏定义,非真正函数。
范例
/* 找出 str 字符串中为阿拉伯数字的字符 */
#include<ctype.h>
main()
{
char str[]="123@#FDsP[e?";
int i;
for(i=0;str[i]!=0;i++)
if(isdigit(str[i])) printf("%c is an digit character\n",str[i]);
}