我想对数组执行一些操作,最终目标是做一个简单的加密。但无论如何,我的数组长度为458个字符,主要由字母和一些逗号,句点等组成。我尝试从数组的最后一个字符开始,并转到数组中的第一个字符和大写字母。它会正确读取最后一个字符“”,但是for循环中的下一步就像4个字符并略过几个字母。我的控制逻辑有问题吗?循环逻辑,加密数组C++
void EncryptMessage (ofstream& outFile, char charArray[], int length)
{
int index;
char upperCased;
char current;
for (index = length-1; index <= length; --index)
{
if (charArray[index] >= 'A' && charArray[index] <= 'Z')
{
upperCased = static_cast<char>(charArray[index]);
current = upperCased;
outFile << current;
}
else
{
charArray[index]++;
current = charArray[index];
}
}
}
这个工程,但我得到真正奇怪的输出,这是随机的顺序,没有一个字母是大写的 – user1193717 2012-04-04 15:59:48
没关系问题是在else语句中,索引再次增加了一个不必要的增量。现在完美工作 – user1193717 2012-04-04 16:05:16
你想只将小写字母改为大写字母吗? – hmjd 2012-04-04 16:06:01