If you want to index the array using two subscripts words[i][j]
, then you need to do two allocations (well, you could make it one if you're really confident in your handling of pointers, but you'd do better with two if you're asking this question).
You need to allocate enough space for the pointers, and enough space for the data:
char **words = malloc(wordCount * sizeof(*words));
char *data = malloc(wordCount * MAX_WORD_LENGTH);
if (words == 0 || data == 0)
{
free(data);
free(words);
...report error?...
}
for (int i = 0; i < wordCount; i++)
words[i] = data + (i * MAX_WORD_LENGTH);
...now you can use words[i][j] to access the jth character of the ith word...