I'm writing a spellchecking program using a hash table. The hash table (a char * array) serves as the dictionary, storing words inputted from the file wordlist.txt. When I call the lookup function, a floating point exception occurs. Any suggestions you have on how to find what's causing the exception would be greatly appreciated.


Descriptions of the attached files:

1. spellcheck.cpp contains the main function, calling the Dictionary class member function "add" on every word in the file wordlist.txt.
2. hashTable.cpp contains definitions for functions in the Dictionary class. The "add" and "getIndex" functions are the only ones that are functional right now.
3. hashTable.h contains declarations.
4. wordlist.txt contains all the words that need to go in the dictionary.
5. input.txt is the input to the program, but isn't actually being used for anything yet.

First thing to look for are cases where you are maybe dividing by zero or attempting to take the square root of a negative number. Output your floating point values before using them as a sanity check.

> Any suggestions you have on how to find what's causing the exception would be greatly appreciated.
Use a debugger.
It will catch the exception, and then show you the line of code that TRIGGERED the exception.

From there, you look back through the code to mentally construct how it got to that point until you find where the root CAUSE of the problem happened (this is the bug).

Fix the bug, and re-test.

Thank you both very much! You helped a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.