c语言大小写字母变换,C语言学习:任意大小写字母转换

实现任意大小写字母转换的代码:

#include

#define DAXIE(x) (x>='A' && x<='Z') //判断是大写字符。

#define XIAOXIE(x) (x>='a' && x<='z') //判断是小写字符。

#define ZHUANXIAOXIE(x) (x-'A'+'a')//转为小写

#define ZHUANDAXIE(X) (x-'a'+'A')//转为大写

int main()

{

char str[100];

int i;

gets(str);

for(i = 0; str[i]; i ++)

if(DAXIE(str[i])) str[i] = ZHUANXIAOXIE(str[i]);//如果是大写字符,转为小写。

else if(XIAOXIE(str[i])) str[i] = ZHUANDAXIE(str[i]);//如果是小写字符,转为大写。

puts(str);//输出结果 return 0;

}

a707d3128085683c2f6bd2b4efdc141c.png

利用int tolower(int ())函数,将大写字母转换成小写字母。

例子:

#include

main(){

char b[] = "qWErt222;!#$";

int i;

printf("before tolower() : %b\n", b);

for(i = 0; i < sizeof(b); i++)

b[i] = tolower(b[i]);

printf("after tolower() : %b\n", b);

}

article-938975-1.html

同样,也可以利用利用int tolower(int ())函数,将小写字母转换成大写字母。

例子:

#include

main(){

char a[] = "qWErt222;!#$";

int i;

printf("before toupper() : %a\n", a);

for(i = 0; i < sizeof(a); i++)

a[i] = toupper(a[i]);

printf("after toupper() : %a\n", a);

}

article-938975-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值