0

I updated my hash function to make the code faster, it makes a hash table and stores word with the same first three letters in one linked list, i.e words starting with aaa will go together, words starting with aab will go together and so on and so forth, but because of this I am getting segmentation fault on the larger files like holmes, it works quite well on smaller files like lalaland and gives good time. I do not get a segmentation when I use a simpler hash function which stores words with same first letter together. below is my code for dictionary.c

EDIT : I have removed my code for academic honesty, as suggested by Cliff 42, I forgot about the apostrophes while writing the hash function, once I adjusted for that everything was working fine.

1

You're on the right track. The problem is definitely within the hash function.

I added a printf statement to print every word being checked to find out which word was triggering the seg fault. The culprit is a'n't.

So, looking back at your hash function, there's a big oversight. What happens when the second or third letter is an apostrophe? Right now, it generates a negative hash, at least for the word a'n't.

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

2
  • Thanks, this was the problem, in check I implemented an if statement to overcome that. I should've used printf instead of debug50, will keep it in mind from now on. – Somit Jain Sep 21 '19 at 13:44
  • They're both useful tools. Printf is especially useful when you have to run through massive data to get to the error, or when debug sometimes masks seg faults. – Cliff B Sep 21 '19 at 13:46

You must log in to answer this question.

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