Originally Posted by
Blasz
As a string of arrays is a double pointer already, unfortunately a pointer to this will be a tripple pointer.
That's your mistake. A double pointer is a pointer. What does it point to? An array of strings. Does it have to always point to the same array? NO! You can reassign it to the value of some other double pointer and vice versa. You do not need any further "pointer to the pointer". This is why I suggested this:
Code:
typedef struct {
char **array1; // these are pointers to an array of strings!
char **array2;
} info;
char **x = malloc(sizeof(char*)*10); // an array of strings!
a.array1 = x;
Right now it points to the same thing as x (because a.array1 == x) but it can be reassigned to any other equivalent structure later (in fact, you could just malloc a.array1 and not bother with x and y -- malloc is an assignment, so you could still reassign it to something else afterward.)
Now, if later you want to switch which array of strings a.array1 points to, eg, let's reverse them:
Code:
char **tmp;
tmp = a.array1;
a.array1 = a.array2;
a.array2 = tmp;
Presto! The double pointer does is not permanently attached to any particular array of strings (that would be something like "char array[10][16]", which is not a double pointer). It can be reassigned. So you still do not have a justification for the ***ptptp. The only way that could be justified is if at some point you want to use a.array1 as a pointer to an array of an array of strings:
Code:
char ***ptptp = malloc(sizeof(char**)*10); // 10 arrays of strings;
But if it is always just going to be an array of strings, you will never need that added level of indirection. All it is going to do is make your code more awkward, as this seg fault demonstrates. It will also make it less efficient, because this:
Means loading the address in p, dereferencing it to the value it points to (so loading another address) whereas this:
Simply means loading one address "directly". Make sense?