I just finished my pset5 and when I try to run valgrind with help50, it appears that

Looks like you're trying to use a variable that might not have a value? Take a closer look at line 115 of dictionary.c.

However, I did assign a value to that variable in the previous line. Here is my code:

for (int i = 0; i < N; i++)
    node *path = hashtable[i]->next;
    while (path != NULL)
        node *tmp = path;
        path = path->next;
return true;

Can anybody help me solve this and explain why this happens?


The error probably has its origin in load. Did you explicitly assign a value to every hashtable[i]->next pointer?

  • @curiouswiki not really sure as the only thing I did with hashtable[i] -> next was the following where index1 = hash(word) if (hashtable[index1] == NULL) { hashtable[index1] = new_node; } else { new_node->next = hashtable[index1]->next; hashtable[index1]->next = new_node; }
    – Omi11
    Aug 5 '19 at 16:30
  • That looks like you didn't set hashtable[index1]->next unless the node already existed there.
    – curiouskiwi
    Aug 5 '19 at 20:16
  • @curiouswiki so you are saying the error happens because I don't use hashtable[index1] unless the no de already exists and shloud use hashtable[index1] - >next = new_node; when nothing is there. Thank you. I now understand why it happens
    – Omi11
    Aug 5 '19 at 20:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .