So I'm trying to deallocate memory allocated before but I keep getting an invalid pointer error whenever I run my code.
- here's the code http://rextester.com/WWYE3429
More Details,
I have an array of character pointers.
I initialized all of them to character pointers with values.
The problem happens when I try to free the pointers.
I free all the pointers at all locations in the array
Then free pointer to the array itself
Expected Output
The code should compile with no errors but I keep on getting an invalid pointer error whenever I compile it.
You are trying to free pointers to character literals, which is illegal. Not o mention that you have memory leak: pointers memory allocated on line 27 overwritten on lines 35-37.
You probably want to copy content of literal to the allocated memory. Use srcpy/strncpy.