c++ - 错误:访问冲突写入位置。在 0x52CEE39 (uncrtbased.dll) 处引发异常
问题描述
这是一个类似于 MS Word 的替换功能。句子是原文。ind 是用户想要替换的单词的起始索引。(我已经从句子数组中找到了单词的索引并将它们存储在 ind 中),wlength 是要替换的单词的长度。Temp 是我存储结果的地方。nword 是要代替旧词的新词编辑:所有数组大小相同,所有数组都绰绰有余,所有数组都以空结尾
void replace(char sentence[], char ind[], int wlength, char temp[], char nword[])
{
int a = 0, x = 0, t = 0, j = 0;
for (int i = 0; i < stringlength(ind); i++) {
while (a < ind[i]) {
temp[t] = sentence[a];
t++;
a++;
}
a = a + wlength;
t = t + 1;
strcat(temp, nword); // <---- Error
}
for (int x 0; x < stringlength(temp), x++)
cout << temp[x];
}
解决方案
推荐阅读
- flutter - developer.apple.com 中没有带有标识符的 App ID
- java - 这种正负前瞻的组合有什么作用?
- javascript - 如何在服务器端验证 Nuxt?
- c++ - 访问 Mat 中出错的图像的像素
- c - fgets() 和 scanf() 不能同时正常工作。遇到缓冲区问题
- html - 如何将包括所有内容的 HTML 页面布局更改为从右到左
- html - 外部 CSS 和 HTML 未链接
- python - 如何将列复制到另一个数据框但允许重复
- redux - Redux 中操作文件的用途是什么?
- makefile - 如何修复构建 CXX 对象 CMakeFiles/tvm_objs.dir/src/target/llvm/codegen_llvm.cc.o 时发生的错误?