bool load(const char *dictionary)
{
FILE *dict = fopen(dictionary, "r");
if (dict == NULL)
{
return false;
}
char word[LENGTH + 1];
while (fscanf(dict, "%s", word) != EOF)
{
node *ptr = malloc(sizeof(node));
if (ptr == NULL)
{
return false;
}
strcpy(ptr->word, word);
int hash_int = hash(word);
ptr->next = table[hash_int]->next;
table[hash_int] = ptr;
word_count++;
}
fclose(dict);
return true;
}
debug50 says there's a problem with this block of code.
ptr->next = table[hash_int]->next;
My code gives segfault and I couldn't see why.Can you help me with that?