You do not need to redistribute the "internal arrays". The contents of the allocated memory is a pointer, and when you redistribute input , then you redistribute the input pointer, not the contents where input points.
A rough ASCII image to show how it works:
First, when you select one entry in the input array, it looks like this:
+----------+ +---------------------------+ input -> | input[0] | -> | What `input[0]` points to | +----------+ +---------------------------+
After redistributing the space for the second record (i.e. input = realloc(input, 2 * sizeof(char*)); )
+----------+ +---------------------------+ input -> | input[0] | -> | What `input[0]` points to | +----------+ +---------------------------+ | input[1] | -> | What `input[1]` points to | +----------+ +---------------------------+
Content i.e. input[0] , remains the same as before redistribution. The only thing that changes is the actual input pointer.
source share