linux C函数练习 一 字符测试函数

字符测试函数函数名函数原型头文件函数功能返回值附加说明
 isalnumint isalnum(int c)#include <ctype.h>检查参数c是否为英文字母或阿拉伯数字,在标准C中相当于使用isalpha ( c ) || isdigit ( c ) 做测试若参数c为字母或者数字,则返回TRUE, 否则返回NULL宏定义,非真正函数
 isalphaint isalpha(int c)#include <ctype.h>检查参数从是否为英文字母,在标准C中相当于使用isupper ( c ) || islower ( c ) 做测试若参数c为英文字母,则返回TRUE,否则返回NULL宏定义,非真正函数
 isasciiint isascii(int c)#include <ctype.h>检查参数c是否为ASCII码字符,也就判断c的范围是否介于0到127之间若参数c为ASCII码字符,则返回TRUE,否则返回NULL宏定义,非真正函数
 isblankint isblank(int c)#include <ctype.h>检查参数c是否为空格字符,也就是判断是否为空格(space)或是定位字符(tab)。空格的ASCII为32,定位字符(tab)的ASCII码则为9.若参数c为空格字符,则返回TRUE,否则返回NULL宏定义,非真正函数
 iscntrlint iscntrl(int c)#include <ctype.h>检查参数c是否为ASCII控制码,也就是判断c的范围是否在0到31之间若参数c为ASCII控制码,则返回TRUE,否则返回NULL宏定义,非真正函数
 isdigitint isdigit(ing c)#include <ctype.h>检查参数c是否为阿拉伯数字0到9若参数c为阿拉伯数字,则返回TRUE,否则返回NULL宏定义,非真正函数
 isgraphint isgraph(int c)#include <ctype.h>检查参数c是否是可打印字符,若c所对应的ASCII码可打印,且非空格则返回TRUE若参数c为可打印字符,则返回TRUE,否则返回NULL宏定义,非真正函数
 islowerint islower(int c)#include <ctype.h>检查参数c是否为小写英文字母若参数c为小写英文字母,则返回TRUE,否则返回NULL宏定义,非真正函数
 isprintint isprint(int c)#include <ctype.h>检查参数c是否为可打印字符,若c所对应的ASCII码可打印,其中包含空格字符,则返回TRUE若参数c为可打印字符,则返回TRUE,否则返回NULL宏定义,非真正函数
 isspaceint isspace(int c)#include <ctype.h>检查参数c是否为空格字符,也就是判断是否为空格('')、定位字符(’\t')、CR(‘\r')、换行('\n')、垂直定位字符('\v')或者翻页('\f')的情况若参数c为空格字符,则返回TRUE,否则返回NULL宏定义,非真正函数
 ispunctint ispunct(int c)#include <ctype.h>检查参数c是否为标点符号或者特殊符号。返回TRUE也打标参数c为非空格、非数字、非英文字母若参数c为标点符号或者特殊符号,则返回TRUE,否则返回NULL宏定义,非真正函数
 isupperint isupper(ing c)#include <ctype.h>检查参数c是否为大写应为字母若参数c为大写英文字母,则返回TRUE,否则返回NULL宏定义,非真正函数
 isxdigitint 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 $@

 

转载于:https://www.cnblogs.com/Eastsong/p/3569106.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值