To allocate the bank:
wordBank = malloc(wordCount * sizeof(char *));
To allocate individual words:
char *addWord(char **wordBank, size_t idx, char *word) {
wordBank[idx] = malloc(strlen(word) + 1);
// this is how you pass a word
strcpy(wordBank[idx], word);
return wordBank[idx];
}
// how you pass the wordBank:
addWord(wordBand, index, someWord);
But having more instructions in the assembly is not necessarily bad. A constant overhead is generally not a problem in programming. I would use std::string
and std::vector<string>
and spend my time on real problems. At least not on debugging mallocs and frees, assigning and testing NULL pointers.