C++//将1D字符数组转换为大写

C++ // Converting a 1D array of chars to uppercase

本文关键字:转换 字符 1D C++ 数组      更新时间:2023-10-16

我需要修改一个字符的1D数组,并将该数组中包含的所有字母放入大写字母中,然后打印出来(并用大写字母保存数组)。

这就是我的功能,但我不确定我还必须做什么才能让正常工作

void putInUppercase(char text[]) {
assert(isValidText(text)); 
int index(0);
while (text[index] != EOT)
    putchar(toupper(text));
cout << text[index];
++index;
}

text是包含字符的数组。

听起来像是你想要的:

      text[index]=toupper(text[index]);

而不是

否则,您将尝试写入两次输出,并且永远不会更新数组

此外,while循环似乎缺少括号。

void putInUppercase(char text[]) {
    assert(isValidText(text)); 
    int index(0);
    while (text[index] != EOT)
    }
        text[index]=toupper(text[index]);
        cout << text[index];
        ++index;
    }
}