This answer is based on the assumption that you do proper handling of your pointers between the part where you allocate memory for 1 element each and where you try to reallocate the memory.
This part
// realloc to correct size
for(int a = 0; a < word_nb; a++)
{
*(word_list + (word_nb-1)) = (char *)realloc(*(word_list + (word_nb-1)), sizeof(word));
}
can be written much more readable like this:
// realloc to correct size
for(int a = 0; a < word_nb; a++)
{
word_list[word_nb-1] = realloc(word_list[word_nb-1], sizeof(word));
}
In this line you provide a wrong size. sizeof(word)
is the size of the pointer, not the length of the content of your string.
Assuming you enlarged the size allocated for word
properly, you can use strlen(word)+1
to resize your buffer.
1
solved Allocate memory on pointed pointer to char