首页 > 解决方案 > 错误:访问冲突写入位置。在 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];
}

标签: c++arrayscharacterc-strings

解决方案


推荐阅读