Skip to main content
2 of 2
added 435 characters in body
ChrisG
  • 7.4k
  • 2
  • 17
  • 26

There is one mistake here:

while (fgetc(ptr) != EOF)

doesn't just work as a condition, but it does read a char and moves on, so next time you read a string it's gonna miss the first char of the word because it was read by fgetc(). Fix that and report back. I would suggest you use the fscanf() in your loop condition instead (but then remove it from inside the body of the loop).

Also, you would be better of declaring table as node* table[n], so that the members of table are just pointers to nodes, not nodes themselves. In fact, you never use the nodes created in your table. You just use their next attribute, which is itself a pointer to node.

Maybe you are trying to read the word stored in table[i] somewhere in your code, but since there is nothing there you get the segfault.

ChrisG
  • 7.4k
  • 2
  • 17
  • 26