0

I finished all the TODO functions and fixed all the errors, but the program takes 20-25 seconds to output anything, the dictionary load time is 4.3 seconds in the output, the total time is 4.6 seconds, but it takes more than 20 for the loading cursor in the terminal to stop blinking and getting the output. When I use valgrind, it just displays the first 3 lines,and gets stuck until I press ctrl-c.

When I run the same program in my terminal(linux), it instantly runs, and the dict load time is the same.

When I run check50, I get the following output for everything after compile check.

:( handles most basic words properly did not find "MISSPELLED WORD..." Log running ./speller basic/dict basic/text... checking for output "MISSPELLED WORDS WORDS MISSPELLED: 0 WORDS IN DICTIONARY: 8 WORDS IN TEXT: 9 "...

Speller and all other files are unchanged, my dictionary.c file is attached. dictionary.c

1

We don't have to preserve a specific order in those linked lists. It's much faster to insert a node at the beginning of the linked list.

Make the current list head the "next" of your new node, then make your new node the list head.

Edit: More "odd" findings, actually breaking, not just slowing down your programme:

Your unload can contain an infinite loop. Just try it with the small dictionary. The culprit is your continue; shortcut, which does not add value (the case is already covered by the for loop's condition), but means index++; is never reached if any of the linked lists is empty. I would suggest a for (int index = 0; index < N; index++) instead of distributing those things, that would have prevented this particular mistake from happening.

Also, use-after-free. You free(temp_ptr) and then temp_ptr = temp_ptr->next, using the next of what you just freed. Use another variable to get the "next" first, and then free the node.

4
  • This did speed up the code, but check50 still outputs it cannot find MISPELLED WORDS. My output is exactly similar to the staff solution, but it doesn't pass in check50, here's a screenshot of my check50 output : drive.google.com/file/d/1WTFYXb_VdRwPPzTCwXk2wc32wEIxzxb3/… – Jeevan Kumar Jul 1 '19 at 15:49
  • Pretty confusing, it's caused because they use a small dict, and your programme never returns from unload. Added to my answer. – Blauelf Jul 2 '19 at 12:27
  • It calls unload before printing all the information, so if it gets stuck in an infinite loop, nothing is ever printed to the console, checker will terminate the programme after a timeout. Initially thought the timeout were due to adding to the end of the linked lists, but nothing beats an infinite loop. – Blauelf Jul 2 '19 at 15:22
  • Thanks!! That did it, I was checking the check() function again and again and turns out the problem was in unload(), the program never returned the output as it didn't return from unload(). – Jeevan Kumar Jul 2 '19 at 15:23

You must log in to answer this question.

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