C ++如何将char数组的第三个字母变成大写字母?

时间:2018-11-18 19:15:15

标签: c++ arrays primes toupper

目前,我已经弄清楚了如何使每个元音变成'!'并且它确实起作用。我为此使用了bool isVowel()函数。

现在我想每三个字母大写一次。我的数组是char aPhrase[15] = "strongpassword"

while (aPhrase[i])
{
c=aPhrase[i];
putchar(toupper(c));
i+=3;
}

这只会让我SOPSRR而不是Str!ngP!sSw!Rd

1 个答案:

答案 0 :(得分:2)

while (aPhrase[i]) {
    c = aPhrase[i];
    if (isVowel(c)) 
        c = '!';
    else if ((i % 3) == 0)
        c = toupper(c);
    putchar(c);
    ++i;
}