我的问题是,当内部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;
}
}
}
答案 0 :(得分:2)
我想这个
intDestinationIndex - 1;
应如下所示:
intDestinationIndex -= 1;