In your original implementation, free(list->array) is necessary because you use malloc to allocate a new dynamic array. Using realloc, this is no longer necessary and would in fact be a mistake. The loop that loops to free(list->array[i]) is a mistake because you copied those pointers over to the new dynamic array, thus freeing them here means that the new dynamic array contains pointers that are no longer valid.Originally Posted by blackfox_1109
Your learning materials should contain a declaration of realloc that you can refer to. Or, if you are using a system with man pages, running man realloc might work. Or, you can search the Web.Originally Posted by blackfox_1109
EDIT:
Oh, actually, the loop that "copy the contents of list->array into newarray" is also wrong because you failed to allocate space for the pointers to point to. With strcpy, you did not copy pointers, but rather copied the contents of what the pointers pointed to.
I suggest that you work on something simpler: try implementing an ArrayList struct for a 1D dynamic array of ints, or maybe a string struct. Doing 2D without having done 1D is harder than doing 1D and then 2D.