Basically, I want to get the size of a double char pointer, EG char **x;
Not the elements of the individual arrays, but the actual number of elements inside the pointer.
I don't want to use vectors or Strings either, I know how to do it that way, but it looks ugly.
So if I could get some feedback on this, it would be appreciated. :-)

How to get the size of a double char pointer?
frrobi
int xsize = 20;
char** x = malloc(xsize * sizeof(char*));
// Initialize it first
int ix;
for (ix = 0; ix < xsize; ++ix) x[ix] = NULL;
// Now allocate the elements from something, say char* table[]
for (ix = 0; ix < xsize; ++ix) {
x[ix] = malloc((strlen(table[ix]) + 1) * sizeof(char*));
strcpy(x[ix], table[ix]);
}
// Go to town...
...
// Cleanup
for (ix = 0; ix < xsize; ++ix) free(x[ix]);
free(x);
I haven't tried it, please excuse any typing mistakes.
Last but not least, there are a million ways to really mess up your heap using code like this. Vectors and Strings were invented to avoid the dreaded General Protection Fault and random crashes due to heap corruption. Save yourself loads of time debugging crashing programs and hit the books instead.
Koolchamp
Brian Pos
Rob Daigneau
If you’re allocating on the heap then _msize() might be quite useful for getting the size in bytes.
tkim11
not easy without element count
Kuphryn
sherifsoft2002
J. Newman
char **x = new char* [20];
it would have 20 (not yet initialized) elements.