这是一个类似于MS Word的替换功能。句子是原文。 ind是用户要替换的单词的起始索引。 (我已经从句子数组中找到了单词的索引,并将它们存储在ind中),wlength是将要替换的单词的长度。 Temp是我存储结果的地方。 nword是将取代旧单词的新单词 编辑:所有数组的大小相同,所有数组都足够,所有数组都以null结尾
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];
}