【Linux C】字符测试函数

一,概述

        字符测试函数 包含在头文件 <ctype.h>中

        这些都是宏定义,而非真正函数。


1)isalnum  测试字符是否为英文字母或数字


#include <stdio.h>
#include <ctype.h>
int main()
{
   char str[]="12#$%sdfsfsf";
   int i;
   for(i=0;str[i]!=0;++i)
	if(isalnum(str[i]))
		printf("%c is an alphanumberic character\n",str[i]);
   return 0;
}

2)isalpha 测试是否为英文字母

#include <stdio.h>
#include <ctype.h>
int main()
{
   char str[]="12#$%sdfsfsf";
   int i;
   for(i=0;str[i]!=0;++i)
	if(isalpha(str[i]))
		printf("%c is an alpha character\n",str[i]);
   return 0;
}

3)isascii  测试是否为ASCII字符

#include <stdio.h>
#include <ctype.h>
int main()
{
   int i;
   for(i=125;i<130;++i)
	if(isascii(i))
		printf("%d is an ascii character\n",i);
        else
		printf("%d is not an ascii character\n",i);
   return 0;
}

4)isblank      测试字符是够为空白字符

5)iscntrl(c)   测试是否为ASCII控制码,也就是判断是否在 0 -31之间

6)isdigit       测试是否为阿拉伯数字

7)isgraph    测试是否为可打印字符,不是空白字符(看10)

8)islower     测试是否为小写英文字母

9)isprint       测试字符是否为可打印字符  类似 isgraph

10)isspace  测试字符是否为空白字符 ‘ ’、'\t'、'\n'、'\f'、'\v'

11)ispunct   测试是否为标点符号或特殊符号

12)isupper  测试是否为大写英文字母

13)isxdigit   测试字符是否为十六进制数字 0 1 2 3 4 5 6 7 8 9  a b c d e f A B C D E F 



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值