I'd like to have an array of fixed length strings in c in the form of a pointer so I can dynamically allocate the memory for it. I can see plenty of reference to arrays of pointers to string, but not to what I want to achieve.
What I want is to be able to declare a pointer to char[MAX_STRING_LENGTH] so I can then dynamically allocate a contiguous block of memory for all the strings:
char *(names[MAX_STRING_LENGTH]); // This won't work
names = (some cast)malloc(NUM_STRINGS * MAX_STRING_LENGTH);
And then access the array of strings:
strcpy(name, names[stringIndex]);
How do I declare the variable and cast the pointer from malloc?