大小写转换

基本类型 / 字符串

char str[] = "Lower And Upper";
char lower[sizeof str];
char upper[sizeof str];
char swapCase[sizeof str];

//逐个字母处理,结尾的零也会被复制;
//ctype 函数需要 unsigned char,且只识别 ASCII 字母
for (size_t i = 0; i < sizeof str; i++) {
    unsigned char c = str[i];
    lower[i] = tolower(c);
    upper[i] = toupper(c);
    swapCase[i] = isupper(c) ? tolower(c) : toupper(c);
}
//lower is "lower and upper"
//upper is "LOWER AND UPPER"
//swapCase is "lOWER aND uPPER"

printf("lower is %s\n", lower);
printf("upper is %s\n", upper);
printf("swapCase is %s\n", swapCase);