// Loads dictionary into memory, returning true if successful, else false
bool load(const char *dictionary)
{
// TODO
FILE* dict = fopen(dictionary,"r");
if (dict == NULL)
{
return false;
}
//initialize table
for (int i = 0; i < N; i++)
{
table[i] = NULL;
}
//char array
char word[LENGTH + 1];
//read from file
while(fscanf(dict,"%s\n",word) != EOF)
{
node *new_node = malloc(sizeof(node));
/* so we know where the end of the linked list is */
new_node->next = NULL;
if(new_node == NULL)
{
printf("Couldn't malloc new node\n");
fclose(dict);
return false;
}
/*hash table*/
strcpy(new_node->word , word);
hash_value = hash(word);
if(table[hash_value] == NULL)
{
table[hash_value] = new_node;
}else
{
new_node -> next = table[hash_value];
table[hash_value] = new_node;
}
word_count++;
}
fclose(dict);
return true;
}
I've tried everything i can't seem to find whats wrong. Am I assigning my file incorrectly or is my implementation of fscanf wrong ? I tried debugging with debugg50 and i found that my while loop wasn't executing at all.