C语言任务1---- 介绍<ctype.h>中的几个函数

<ctype.h>是c标准库里的头文件,提供了一些用于测试和映射字符的函数,下面将介绍其中的一些函数。

1.isascii( )函数

isascii是c语言中的字符检测函数,通常用于检测字符c是否为ASCII码字符;

参数类型:int

返回值:若为ASCII码字符返回true(非0),否则返回null(0);

​
​
​
#include<stdio.h>
#include<ctype.h>

int main()
{
	for(int i=125;i<=130;i++)
    {
		if(isascii(i)!=0)
        {
			printf("%d是ascall码字符\n",i);
		}
        else
        {
			printf("%d不是ascall码字符\n",i);
		}
	}
} 

​

​

​

运行结果:

 

2,isalpha()函数

isalpha( )判断字符是否为 英文字母

参数:int

返回值:若为英文字母,返回true(非0),否则返回0;

#include<stdio.h>
#include<ctype.h>
int main()
{
	printf("%d\n",isalpha('a'));
	printf("%d\n",isalpha('A'));
	printf("%d\n",isalpha('9'));

    return 0;
} 

运行结果:

3. isdigit()

isdigit()函数用于判断字符是否为阿拉伯数字

参数:int

返回值:若为阿拉伯数字,返回非0整数,否则返回0;

​
#include <stdio.h>
#include <ctype.h>

int main()
{
    char a = 'c',b = '1';


    printf("%d\n",isdigit(a));
    printf("%d\n",isdigit(b));

    return 0;
}

​

 运行结果:

4.isalnum() 

isalnum函数用于判断字符是否为字母或数字;

参数:int

返回值:若为字母或数字,返回非0整数,否则返回0

​
#include <stdio.h>
#include <ctype.h>

int main()
{
    char a = 'c', b = '2', c = '@';
    
    printf("%d\n",isalnum(a));
    printf("%d\n",isalnum(b));
    printf("%d\n",isalnum(c));

    return 0;
}

​

 运行结果:

5.isblank( ) 

isblank()函数用于检查字符是否为空白字符('space' || 'tab');

参数:int

返回值:如果为空白字符,返回非0整数,否则返回0; 

 

#include <stdio.h>
#include <ctype.h>

int main()
{
    char a = 'c', b = '3', c = ' ';
   
    printf("%d",isblank(a));
    printf("%d",isblank(b));
    printf("%d",isblank(c));

    return 0;
}

运行结果:

6,isspace() 

它用来检查参数c是否为空白字符。也就是判断是否为空格(' ')、水平定位字符('\t')、归位键('\r')、换行('\n')、垂直定位字符('\v')或翻页('\f')的情况。

参数:int

返回值:如果为空白字符,返回非0整数,否则返回0;

#include <stdio.h>
#include <ctype.h>

int main()
{
	printf("%d\n",isspace(' '));
	printf("%d\n",isspace('	'));
	printf("%d\n",isspace('9'));
}  

运行结果: 

 

 7、islower()

这个函数用来检查参数c是否为小写英文字母。

参数:int

返回值:如果为空白字符,返回非0整数,否则返回0;

#include <stdio.h>
#include <ctype.h>

int main()
{
	printf("%d\n",islower('a'));
	printf("%d\n",islower('A'));
	printf("%d\n",islower('9'));

    return 0;
} 

 运行结果:

 8、isupper() 

此函数用来判断字符c是否为大写英文字母, 

参数:int

返回值:如果为空白字符,返回非0整数,否则返回0;

#include <stdio.h>
#include <ctype.h>

int main()
{
	printf("%d\n",isupper('a'));
	printf("%d\n",isupper('A'));
	printf("%d\n",isupper('9'));

    return 0;
}  

运行结果:

 

  9、toupper( )

这个函数用来将字符c转换为大写英文字母; 

参数:int

返回值:返回对应的大写字母

#include <stdio.h>
#include <ctype.h>
int main()
{
	printf("%c\n",toupper('a'));
	printf("%c\n",toupper('b'));
	printf("%c\n",toupper('A'));
	printf("%c\n",toupper('9'));

    return 0;
}  

运行结果:

 

 10、tolower()

此函数用来 将字符c转换为小写英文字母; 

参数:int

返回值:返回对应的小写字母

#include <stdio.h>
#include <ctype.h>

int main()
{
	printf("%c\n",tolower('a'));
	printf("%c\n",tolower('b'));
	printf("%c\n",tolower('A'));
	printf("%c\n",tolower('B'));
	printf("%c\n",tolower('9'));

    return 0;
} 

 运行结果:

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Front row sailor

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值