字符数组复制错误

Array of characters copy error

我的问题是,当内部 for 循环退出并返回到外部 for 循环时,它会停止向字符串指针 pstrDestination 添加字符。有人可以向我解释一下吗,我没有终止字符数组,所以它仍然应该写入,不是吗?

// Does it match
if (strcmp(strCompareString, pstrToFind) == 0)
{

    // Reset the index of the found letter
    intFoundLetterIndex = (intFoundLetterIndex - intCompareIndex);

    // Add the characters from source to destination.
    for (intSourceIndex = 0; intSourceIndex < intSourceLength; intSourceIndex += 1)
    {

        pstrDestination[intDestinationIndex] = pstrSource[intSourceIndex];
        intDestinationIndex += 1;

        // Are we at the beginning of the target word
        if (intSourceIndex == intFoundLetterIndex)
        {

            // Add the replacement characters to the destination.
            for (intNewIndex = 0; intNewIndex < intReplaceWithLength; intNewIndex += 1)
            {

                pstrDestination[intDestinationIndex - 1] = pstrReplaceWith[intNewIndex];
                intDestinationIndex += 1;

            }

            intSourceIndex += intToFindLength;
        }

    }

}

我觉得这个

intDestinationIndex - 1;

应该是这样的:

intDestinationIndex -= 1;

我能想到的最好的是,Visual Studio 2013 IDE 正试图给我一个大大的拥抱。 它正在为我终止字符串。 如果我将索引后退 1 并将数组中的点设置为等于“”。然后循环按预期执行,因为我写了终结符。

在我添加的内循环之后;

pstrDestination[intDestinationIndex - 1] = ' ';