0

I am getting a segmentation fault with my speller program. I've placed check,unload and size under comments in an attempt to identify the cause of my problem. I belive my implementation of load or the hash function might cause my crash. Please help me fix this problem.

Thank you in advance !

  • removed due academic honour policy
1

You're right that it is in the load function. The seg fault occurs near the end.

  previous -> next = new;

The problem occurs when you are adding the first word for a given hash index to the hashtable array. At this point, previous is still set to null. If you try to assign something to previous->next when previous = null, it seg faults.

Next, you have a problem with the following:

if(hashtable[index] == NULL)
{
   new -> next = NULL;
   hashtable[index] = NULL;
}

This is supposed to store the pointer to the new word in the hashtable. Instead, it doesn't do anything with hashtable[index].

Later, you free(new). This will have the effect of releasing the memory of the last word processed, effectively throwing away the last word that you processed.

Also, I noticed a lot of return statements in your code. Essentially, you will hit a return statement one way or another while processing the first word! As soon as you hit one, the function is going to return to the calling program, so you will never process more than one word, and certainly never process a whole dictionary.

This is just what I saw while looking for the seg fault, there may be other issues too.

If this answers your question, please click the check mark to accept the answer. Let's keep up on forum housekeeping. ;-)

1
  • I swear I just checked with valgrind and seen " previous -> next = new;" as a problem, such a synchronization. Thank you a lot for your help! Cheers,mate !
    – Gabriel
    Nov 28 '15 at 17:58

You must log in to answer this question.

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