I am writing a program, and in my program I need to Copy info from 1st 1D array into 2D array, but every time there is a \n in 1d array, it suppose to go into different slots in 2D array. For example if 1D array is Hello\nWorld in 2d array it will become hello/n in first slot and world in the second slot.
Here is my code But I am getting segmentation error. The array called chars is already made in my program before this step.
words = (char**) malloc(numWords*sizeof(char));
int copyCountForChars=0;
int copyCountForWords=0;
while(copyCountForWords <= numWords)
{
words[copyCountForWords][copyCountForChars] = chars[copyCountForChars];
// printf("%c",chars[copyCountForChars]);
if(chars[copyCountForChars] == '\n')
{
// printf("%c",chars[copyCountForChars]);
copyCountForWords++;
}
copyCountForChars++;
}