转载 :
https://blog.csdn.net/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;
}