我用haiku模板打开一个带有*的文件,以指示要替换的单词,然后将文本复制到og 2d数组中。我有一个新的2d数组可将更改后的文本复制到其中。我从函数segmentation fault (core dumped)
中收到错误消息changeLine
。 index = line
是从og数组开始复制的对象,i
是要复制的字符。功能如下:
int randHaiku(int& index)
{
index = ((rand() % 16) * 3); // index of first of 3 lines to be copied
return(index);
}
void changeLine(char fillWords[3][15], char ogLine[51][50], char newLine[3][50])
{
int index = randHaiku(index);
for (index; index < (index + 3); index++)
{ for (int i = 0; i < strlen(ogLine[index]); i++)
{ if (ogLine[index][i] != '*') // replacing * with user's word
{ newLine[index][i] = ogLine[index][i]; }
else {strcat(newLine[index], fillWords[index]);
strcat(newLine[index], &ogLine[index][++i]);
i = strlen(ogLine[index]); }
}
}
cout << newLine;
}
我不知道是什么导致了我的错误,但我知道它一定是来自changeLine
。