I\'m trying to build a dynamically grown array of strings. Neither the number of strings nor the length of each string is known at compile time. Here\'s the code I came up w
The following statement makes both result[0]
and temp
point to the same memory address:
result[0]=temp;
Having performed the above assignment, you then free(temp)
and try to access result[0]
:
free(temp);
printf ("%s \n", result[0]);
This is undefined behaviour, since you're accessing the memory that's just been deallocated.
The same goes for the identical code you have for result[1]
.