I'm trying to figure out how to free the memory for an array of character pointers (string literals), but I can't quite get the syntax. This is how I'm declaring and initializing the arrays.
char * words[] = { "THESE", "ARE", "SOME", "WORDS" };
I've tried doing this...
free(words);
And this...
for(i = 0; i < 4; i++) {
free(words[i]);
}
But the first one causes some sort of invalid pointer error with glibc, and the second one causes a segmentation fault.
So what's the right way to free this memory?
freesomething you didn'tmalloc.