zoukankan      html  css  js  c++  java
  • linux C函数练习 一 字符测试函数

    字符测试函数 函数名 函数原型 头文件 函数功能 返回值 附加说明
      isalnum int isalnum(int c) #include <ctype.h> 检查参数c是否为英文字母或阿拉伯数字,在标准C中相当于使用isalpha ( c ) || isdigit ( c ) 做测试 若参数c为字母或者数字,则返回TRUE, 否则返回NULL 宏定义,非真正函数
      isalpha int isalpha(int c) #include <ctype.h> 检查参数从是否为英文字母,在标准C中相当于使用isupper ( c ) || islower ( c ) 做测试 若参数c为英文字母,则返回TRUE,否则返回NULL 宏定义,非真正函数
      isascii int isascii(int c) #include <ctype.h> 检查参数c是否为ASCII码字符,也就判断c的范围是否介于0到127之间 若参数c为ASCII码字符,则返回TRUE,否则返回NULL 宏定义,非真正函数
      isblank int isblank(int c) #include <ctype.h> 检查参数c是否为空格字符,也就是判断是否为空格(space)或是定位字符(tab)。空格的ASCII为32,定位字符(tab)的ASCII码则为9. 若参数c为空格字符,则返回TRUE,否则返回NULL 宏定义,非真正函数
      iscntrl int iscntrl(int c) #include <ctype.h> 检查参数c是否为ASCII控制码,也就是判断c的范围是否在0到31之间 若参数c为ASCII控制码,则返回TRUE,否则返回NULL 宏定义,非真正函数
      isdigit int isdigit(ing c) #include <ctype.h> 检查参数c是否为阿拉伯数字0到9 若参数c为阿拉伯数字,则返回TRUE,否则返回NULL 宏定义,非真正函数
      isgraph int isgraph(int c) #include <ctype.h> 检查参数c是否是可打印字符,若c所对应的ASCII码可打印,且非空格则返回TRUE 若参数c为可打印字符,则返回TRUE,否则返回NULL 宏定义,非真正函数
      islower int islower(int c) #include <ctype.h> 检查参数c是否为小写英文字母 若参数c为小写英文字母,则返回TRUE,否则返回NULL 宏定义,非真正函数
      isprint int isprint(int c) #include <ctype.h> 检查参数c是否为可打印字符,若c所对应的ASCII码可打印,其中包含空格字符,则返回TRUE 若参数c为可打印字符,则返回TRUE,否则返回NULL 宏定义,非真正函数
      isspace int isspace(int c) #include <ctype.h> 检查参数c是否为空格字符,也就是判断是否为空格('')、定位字符(’\t')、CR(‘\r')、换行('\n')、垂直定位字符('\v')或者翻页('\f')的情况 若参数c为空格字符,则返回TRUE,否则返回NULL 宏定义,非真正函数
      ispunct int ispunct(int c) #include <ctype.h> 检查参数c是否为标点符号或者特殊符号。返回TRUE也打标参数c为非空格、非数字、非英文字母 若参数c为标点符号或者特殊符号,则返回TRUE,否则返回NULL 宏定义,非真正函数
      isupper int isupper(ing c) #include <ctype.h> 检查参数c是否为大写应为字母 若参数c为大写英文字母,则返回TRUE,否则返回NULL 宏定义,非真正函数
      isxdigit int isxdigit(int c) #include <ctype.h> 检查参数c是否为16进制数字,只要c复核下列其中一个情况就返回TRUE 16进制数字:0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F  若参数c为16进制数字,则返回TRUE,否则返回NULL 宏定义,非真正函数
    文件名定义为char_test.c
     
    #include <ctype.h>
    #include <stdio.h>
    
    void main()
    {
    	char str[]="123c@#FDsP[e?";
    	int i;
    	printf("--isalnum function : test char is alphanumeric or not.\n");
    	for ( i =0; str[i] != 0; i++ )
    	{
    		if( isalnum(str[i]) )
    			printf("%c is an alphanumeric character\n", str[i]);
    		else
    			printf("%c is not an alphanumeric character\n", str[i]);
    	}
    	printf("--isalpha function : test char is alphabetic character or not.\n");
    	for ( i =0; str[i] != 0; i++ )
    	{
    		if( isalpha(str[i]) )
    			printf("%c is an alphabetic character\n", str[i]);
    		else
    			printf("%c is not an alphabetic character\n", str[i]);
    	}
    	
    	printf("--isascii function : test char is ascii character or not.\n");
    	for ( i =125; i < 130; i++ )
    	{
    		if( isascii(str[i]) )
    			printf("%d is an ascii character\n", i);
    		else
    			printf("%d is not an ascii character\n", i);
    	}
    
    	printf("--isblank function : test char is blank character (space or tab) or not.\n");
    	char str1[]="123c @#FD	sP[e?";
    	for ( i =0 ; str1[i] != 0; i++ )
    	{
    		if( isblank(str1[i]) )
    			printf("str1[%d] is an blank character:%c\n", i,str1[i]);
    		else
    			printf("str1[%d] is not an blank character:%c\n", i,str1[i]);
    	}
    	
    	printf("--isdigit function : test char is digital character  or not.\n");
    	char str2[]="123c @#FD	sP[e?";
    	for ( i =0 ; str2[i] != 0; i++ )
    	{
    		if( isdigit(str2[i]) )
    			printf("str2[%d] is an digit character:%c\n", i,str2[i]);
    		else
    			printf("str2[%d] is not an digit character:%c\n", i,str2[i]);
    	}
    	
    	printf("--isgraph  isprint function: test char is printable character or not.\n");
    	char str3[]="a5 @;";
    	for ( i=0; str3[i] != 0; i++ )
    	{
    		if( isgraph(str3[i]) )
    			printf("str[%d] is printable character: %d\n",i, str3[i]);
    	}
    	
    	
    	printf("--islower isupper function: test char is lower-case/upper-case character or not.\n");
    	char str4[]="123c@#FDsP[e?";
    	for ( i=0; str4[i] != 0; i++ )
    	{
    		if( islower(str4[i]) )
    			printf("str[%d] is lower-case character: %d\n",i, str4[i]);
    		else if( isupper(str4[i]) )
    			printf("str[%d] is upper-case character: %d\n",i, str4[i]);
    	}
    	
    	printf("--isspace function: test char is white-space character (space/tab//t/n/v/f ) or not.\n");
    	char str5[]="123 c@# FD\tsP[e?\n";
    	for ( i=0; str5[i] != 0; i++ )
    	{
    		if( isspace(str5[i]) )
    			printf("str5[%d] is white-space character: %d\n",i, str5[i]);
    	}
    	
    	printf("--ispunct function: 测试字符是否是标点符号\n");
    	char str6[]="123 c@# FD\tsP[e?\n";
    	for ( i=0; str6[i] != 0; i++ )
    	{
    		if( ispunct(str6[i]) )
    			printf("str6[%d] 是标点符号 : %d\n",i, str6[i]);
    	}
    }
    

      makefile 内容如下:

    all:char_test
    char_test:char_test.c
        gcc $^ -o $@
  • 相关阅读:
    iphone:URL initWithString 返回为空
    android:unable to instantiate activity componentinfo
    android:进度条
    android:spinner
    android:DDMS查看Threads
    android:ListView:convertView.setTag()来设置数据
    iphone:使用UIImagePickerController从IPhone照片库或照相机获取图像
    android:ListView中的getView原理
    android 从assets和res中读取文件
    android:menu.xml
  • 原文地址:https://www.cnblogs.com/Eastsong/p/3569106.html
Copyright © 2011-2022 走看看