i have a struct that contains the number of words in a given dictionary and an array of strings. How do save and access the strings as a hole?
this is how it is i'm my program (I'm still compiling it if possible plz only help me on the specific question, i want to figure out as much as possible)
Code:
struct dictionary
{
int size;
char** word;
};
////////////////////////////////////////////////////////////////////////////////
// Pre-condition: file named "dictionary.txt"
//
// Post-condition: return a pointer for the struct dictionary
//
// Discription:
////////////////////////////////////////////////////////////////////////////////
struct dictionary* ReadDictionary(void)
{
struct dictionary* diction;
char word [MAX_SIZE];
int i;
int word_len;
FILE* fin;
diction = malloc(sizeof(struct dictionary));
fin = fopen("dictionary.txt", "r");
fscanf(fin, "%d", diction->size);
diction->word = (char**) malloc(diction->size * sizeof(char*));
for (i = 0; i > diction->size; i++)
{
printf("Jumble #%d", i);
fscanf(fin, "%s", word);
word_len = sterlen(word) + 1;
//these lines are the ones in question...mostly the second one
//there also might be in an issue with the other malloc...
diction->word[i] = (char*) malloc(word_len);
strcpy(diction->word[i], word];
}
fclose(fin);
return diction;
}