转载 :
https://blog.youkuaiyun.com/linbounconstraint/article/details/80310471
转大写:
char *strupr(char *str)
{
char *orign=str;
for (; *str!='\0'; str++)
*str = toupper(*str);
return orign;
}
转小写:
char *strlowr(char *str)
{
char *orign=str;
for (; *str!='\0'; str++)
*str = tolower(*str);
return orign;
}
常用到的是在ctype.h(C++中是cctype)库文件下定义的函数方法。首先来看一下C下tolower/toupper函数实现原型:
int tolower(int c)
{
if ((c >= 'A') && (c <= 'Z'))
return c + ('a' - 'A');
return c;
}
int toupper(int c)
{
if ((c >= 'a') && (c <= 'z'))
return c + ('A' - 'a');
return c;
}

本文详细介绍了如何使用C语言实现字符串的大小写转换,包括strupr和strlowr函数的具体实现,以及tolower和toupper函数的原型说明。这些函数常见于ctype.h库文件,是进行文本处理时的重要工具。

1万+

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



