如何一次更改2维C字符串数组中的文本?

时间:2018-11-16 17:34:11

标签: c++ arrays string 2d

我用haiku模板打开一个带有*的文件,以指示要替换的单词,然后将文本复制到og 2d数组中。我有一个新的2d数组可将更改后的文本复制到其中。我从函数segmentation fault (core dumped)中收到错误消息changeLineindex = 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

0 个答案:

没有答案