Basically I'm reading from a file and populating a dynamically allocated array with the words that are in the file. I've already read through the file to figure out what numArts is, so I know how many words there are in the array.
This works up until the:
arts[index] = (char*)malloc(strlen(word) * sizeof(char));
strcpy(*(arts + index), word);
if I remove those lines, the printf statment prints what I expect it to. I've tried doing this with pointer arithmetic as well. I just keep getting bus error over and over. From what I can tell and what I've been able to read about dynamically allocating arrays and such I'm doing this correctly. Does anyone see anything wrong with this?
void populateArts(char **arts, FILE *fin, int *numArts)
{
int index;
char* word; /* Temporary holding for each word */
arts = malloc(*numArts * sizeof(char*));
fscanf(fin, "%s", word); /* Skip over category */
/* Fill articles array */
for(index = 0; index < *numArts; index++)
{
fscanf(fin, "%s", word);
printf("word is %s\n", word);
arts[index] = (char*)malloc(strlen(word) * sizeof(char));
strcpy(*(arts + index), word);
}
}