If you're using the 2nd option you need to dynamically allocate the memory for the char**.
i.e, say you're going to store....20 strings at this stage:
So now the top level has been allocated, but there has been no room actually allocated for strings themselves, just the pointers to the strings. To produce a valid pointer you can do it several ways, the easiest being strdup, it will duplicate an existing string into heap memory and give you a pointer to that string, you can then add that pointer to your array:Code:char **strArray = (char**)calloc(20, sizeof(char*));
For example:
It might be easier to envision what this is doing when you consider:Code:char **strArray = (char**)calloc(20, sizeof(char*)); char *derp = "literal static string"; //now, i don't want to risk the "derp" variable being collected or modified somewhere during runtime, so I'll create my own copy of the string (not the pointer to the string, the string itself. strArray[0] = strdup(derp);
So essentially you have an array of pointers-to-string.Code:char** == *char[]
As always, pointers can be a mindfuck.