打印本文 打印本文 关闭窗口 关闭窗口
Linux C 函数参考(字符测试)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1824  更新时间:2009/4/22 23:09:05  文章录入:mintao  责任编辑:mintao
"str[%d] is a white-space character:%d\n",i,str[i]);
}
执行 str[4] is a white-space character:32
str[7] is a white-space character:32
str[10] is a white-space character:9 /* \t */
str[16] is a white-space character:10 /* \t */
 


ispunct(测试字符是否为标点符号或特殊符号)
相关函数 isspace,isdigit,isalpha
表头文件 #inlude<ctype.h>
定义函数 int ispunct(int c)
函数说明 检查参数c是否为标点符号或特殊符号。返回TRUE也就是代表参数c为非空格、非数字和非英文字母。
返回值 v若参数c为标点符号或特殊符号,则返回TRUE,否则返回NULL(0)。
附加说明 此为宏定义,非真正函数。
范例 /*列出字符串str中的标点符号或特殊符号*/
#include <ctype.h>
main()
{
char str[]="123c@ #FDsP[e?";
int i;
for(i=0;str[i]!=0;i++)
if(ispunct(str[i])) printf("%c\n",str[i]);
}
执行 v
@#[?
 


isupper(测试字符是否为大写英文字母)
相关函数 isalpha,islower
表头文件 #include<ctype.h>
定义函数 int isupper(int c)
函数说明 检查参数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(isupper(str[i])) printf("%c is an uppercase character\n",str[i]);
}
执行 F is an uppercase character
D is an uppercase character
P is an uppercase character
 


isxdigit(测试字符是否为16进制数字)
相关函数 isalnum,isdigit
表头文件 #include<ctype.h>
定义函数 int isxdigit (int c)
函数说明 检查参数c是否为16进制数字,只要c为下列其中一个情况则返回TRUE。16进制数字:0123456789ABCDEF。
返回值 若参数c为16进制数字,则返回TRUE,否则返回NULL(0)。
附加说明 此为宏定义,非真正函数。
范例 /*找出字符串str中为十六进制数字的字符*/
#include <ctype.h>
main()
{
char str[]="123c@#FDsP[e?";
int i;
for(i=0;str[i]!=0;i++)
if(isxdigit(str[i])) printf("%c is a hexadecimal digits\n",str[i]);
}
执行 1 is a hexadecimal digits
2 is a hexadecimal digits
3 is a hexadecimal digits
c is a hexadecimal digits
F is a hexadecimal digits
D is a hexadecimal digits
e is a hexadecimal digits
 

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口