cs50x problem set 5 - Is this how to properly load a linked list into a hashtable?
Specifically where it says:
table[i] = n;
Is it loading the correct linked list into the correct bucket?
I'm not getting any errors at the moment but I have a feeling that it isn't correct and will hinder my progress when I move on to the next functions. I just want to make sure that my function puts the linked lists in the correct bucket in regards to the index.
bool load(const char \*dictionary)
{
char word\[LENGTH + 1\];
FILE *file = fopen(dictionary, "r");
if(file == NULL){
printf("Unable to open\n");
return false;
}
while(fscanf(file, "%s", word) != EOF){
node *n = malloc(sizeof(node));
if(n != NULL){
strcpy(n->word, word);
} else{
printf("Unable to open\n");
return false;
}
unsigned int i = hash(word);
node *new_node = malloc(sizeof(node));
table[i] = n;
//Inserts new word onto the link lists
new_node->next = table[i];
table[i] = new_node;
}
fclose(file);
return true;
}