I have a large dictionary of null terminated strings which will be declared in main as char dictionary[MAX_WORDS][MAX_WORD_LENGTH]
, where max_words can be 200000 and max word length can be 50. I want to malloc some space for it with another function like:
char ** AllocateMemory (char dictionary[MAX_WORDS][MAX_WORD_LENGTH])
{
char **p;
{
p = (char **)malloc(sizeof(dictionary));
}
return p;
}
which will be called in main like
int main (void)
{
char dictionary[MAX_WORDS][MAX_WORD_LENGTH];
dictionary = AllocateMemory(dictionary);
}
Can I access this memory in the normal way? (like another function which loops through words in the dictionary like for (i = 0; dictionary[i][0]; i++)
, then the letters in each word). Also I may be missing something here but if I malloc space up for it, I have already created a large amount of space in main by having to declare the dictionary anyway? Please correct me I'm sure im just a bit confused here with malloc.