在C语言中,利用tolower和toupper两个函数实现英文字母的大小写之间的转换
范例1:将s字符串内的小写字母转换成大写字母
#include <ctype.h>
int main()
{
char s[] = "aBcDeFgH";
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);
return 0;
}
范例2:将s字符串内的大写字母转换成小写字母
#include <ctype.h>
int main()
{
char s[] = "aBcDeFgH";
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);
return 0;
}
本文介绍了如何使用C语言中的tolower和toupper函数实现字符串中小写字母到大写字母及反之的转换,并提供了两个示例程序。
165

被折叠的 条评论
为什么被折叠?



