C语言中对字母进行大小写转换的简单方法
发布时间:2020-12-16 03:04:16 所属栏目:百科 来源:网络整理
导读:C语言tolower()函数:将大写字母转换为小写字母 头文件: #include ctype.h 定义函数: int toupper(int c); 函数说明:若参数 c 为小写字母则将该对应的大写字母返回。 返回值:返回转换后的大写字母,若不须转换则将参数c 值返回。 范例:将s 字符串内的小
C语言tolower()函数:将大写字母转换为小写字母 #include <ctype.h> 定义函数: int toupper(int c); 函数说明:若参数 c 为小写字母则将该对应的大写字母返回。 返回值:返回转换后的大写字母,若不须转换则将参数c 值返回。 范例:将s 字符串内的小写字母转换成大写字母。 #include <ctype.h> main(){ char s[] = "aBcDeFgH12345;!#$"; int i; printf("before toupper() : %sn",s); for(i = 0; i < sizeof(s); i++) s[i] = toupper(s[i]); printf("after toupper() : %sn",s); } 执行结果: before toupper() : aBcDeFgH12345;!#$ after toupper() : ABCDEFGH12345;!#$
#include <stdlib.h> 定义函数: int tolower(int c); 函数说明:若参数 c 为大写字母则将该对应的小写字母返回。 返回值:返回转换后的小写字母,若不须转换则将参数c 值返回。 范例:将s 字符串内的大写字母转换成小写字母。 #include <ctype.h> main(){ char s[] = "aBcDeFgH12345;!#$"; int i; printf("before tolower() : %sn",s); for(i = 0; i < sizeof(s); i++) s[i] = tolower(s[i]); printf("after tolower() : %sn",s); } 执行结果: before tolower() : aBcDeFgH12345;!#$ after tolower() : abcdefgh12345;!#$ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |