源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

C语言中对字母进行大小写转换的简单方法

  • 时间:2022-06-13 01:06 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C语言中对字母进行大小写转换的简单方法
[b]C语言tolower()函数:将大写字母转换为小写字母 [/b]头文件:
#include <ctype.h>
定义函数:
int toupper(int c);
函数说明:若参数 c 为小写字母则将该对应的大写字母返回。 返回值:返回转换后的大写字母,若不须转换则将参数c 值返回。 范例:将s 字符串内的小写字母转换成大写字母。
#include <ctype.h>
main(){
 char s[] = "aBcDeFgH12345;!#$";
 int i;
 printf("before toupper() : %s\n", s);
 for(i = 0; i < sizeof(s); i++)
  s[i] = toupper(s[i]);
 printf("after toupper() : %s\n", s);
}
执行结果:
before toupper() : aBcDeFgH12345;!#$
after toupper() : ABCDEFGH12345;!#$
[b]C语言tolower()函数:将大写字母转换为小写字母 [/b]头文件:
#include <stdlib.h>
定义函数:
int tolower(int c);
函数说明:若参数 c 为大写字母则将该对应的小写字母返回。 返回值:返回转换后的小写字母,若不须转换则将参数c 值返回。 范例:将s 字符串内的大写字母转换成小写字母。
#include <ctype.h>
main(){
 char s[] = "aBcDeFgH12345;!#$";
 int i;
 printf("before tolower() : %s\n", s);
 for(i = 0; i < sizeof(s); i++)
  s[i] = tolower(s[i]);
 printf("after tolower() : %s\n", s);
}
执行结果:
before tolower() : aBcDeFgH12345;!#$
after tolower() : abcdefgh12345;!#$
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部