字符数组复制错误
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] = ' ';
相关文章:
- 为什么类中的ostringstream类型的成员会导致";调用隐含删除复制构造函数";错误
- 模板,函数使用错误的构造函数来复制我的对象
- 使用 memcpy() 复制到 std::chrono::milliseconds 会给出错误 -Werror=clas
- C++复制函数重载导致"must be a nonstatic member function"错误
- 为什么我的代码在尝试复制字符数组时引发 C6386 错误?
- 将缓冲区复制到剪贴板 [换行错误]
- 尝试通过memcpy复制大尺寸浮点向量时的分割错误
- 使用复制构造函数的程序输出错误
- 为什么定义复制构造函数会给我错误:无法将类型 'obj&' 的非常量左值引用绑定到类型为"obj"的右值?
- 复制内存给出分段错误
- C:试图将指针值复制到另一个指针中,得到可修改的左值错误
- emplace_back和push_back给出错误'double free or corruption (fasttop)'尽管定义了复制和移动构造函数
- 为什么 std::atomic<std::string> 会给出微不足道的可复制错误?
- STL向量上出现奇怪的复制构造函数错误
- 不可复制类数据成员的统一初始化导致gcc错误
- 错误:使用复制和交换习惯用法的交换函数中"operator="的重载不明确
- 编译器错误:只需要复制省略,但似乎需要移动构造函数(通过编译器)
- 重载赋值运算符函数和复制构造函数中的错误
- C++ 异常的双重释放损坏错误(复制构造函数不起作用)
- 文件I/O错误复制构造函数