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
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
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
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]);
}
1 is an digit character
2 is an digit character
3 is an digit character