the program complies properly but when i use valgrind shows am leaking memory when I open the file in the FILE *file = fopen(dictionary, "r");
bool load(const char *dictionary)
{
// TODO
FILE *file = fopen(dictionary, "r");
if (file == NULL)
{
printf("Could not load file\n");
return 1;
}
// Create a array space in the memory to hold 45 characters
char per_word[LENGTH + 1];
// Loop through every all word int the dictionary with the specified letters
while(fscanf(file,"%s", per_word) != EOF)
{
// Create a new node
node *n = malloc(sizeof(node));
if (n == NULL)
{
return false;
}
// copy the words into the node
strcpy(n->word, per_word);
n->next = NULL;
// HASH THE WORD
int hashed = hash(per_word);
// Check if the word is already at the hashed position in table if not set it to n
if (table[hashed] == NULL)
{
table[hashed] = n;
}
else
{
n->next = table[hashed];
table[hashed] = n;
}
word_count++;
}
return true;
}