zoukankan      html  css  js  c++  java
  • 【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 



  • 相关阅读:
    LinkedListQueue
    LinkedListStack
    redis学习之——Redis事务(transactions)
    redis学习之——持久化RDB 和AOF
    redis学习之——redis.conf配置(基本)文件学习
    评估算法的核心指标
    Vector类
    List接口与ArrayList、LinkedList实现类
    Collection接口
    枚举类
  • 原文地址:https://www.cnblogs.com/secbook/p/2654986.html
Copyright © 2011-2022 走看看