Upper Case or Lower Case String in Linux C
2011-09-06
There is no direct function to convert a string to upper case or lower case in Linux C. Here we collect 2 functions from internet:
#include <ctype.h>
static char* Str2Upper(char *str)
{
if(str == NULL)
return NULL;
char *p = str;
while(*str)
{
*str = toupper(*str);
str++;
}
return p;
}
static char* Str2Lower(char *str)
{
if(str == NULL)
return NULL;
char *p = str;
while(*str)
{
*str = tolower(*str);
str++;
}
return p;
}