我需要将char数组转换为小写字符数组。我还想将一些特殊字符转换为Ä到ä。但是“ASCII-Code”196不在ASCII-128中。如何将它们转换为小写?我可以将它们用作字符串初始化程序,但无法真正处理它们的代码。如果这可能是编译器选项,我在没有c99模式的Linux上使用eclipse CDT(不能使用那个)。
char* toLowerCase(char* text)
{
int length = strlen(text);
char* result = malloc(length); // malloc adds the 0 automatically at result[length]
int i;
for (i = 0; i < length; i++)
if ((text[i] >= 65) && (text[i] <= 90))
result[i] = text[i] | 32;
else
result[i] = text[i];
return result;
}
toLowerCase("hElLo WoRlD ÄäÖöÜü");
// result is "hello world ÄäÖöÜü"
来自tolower()
的 ctype.h
也没有这样做。