954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Floating Point Exception Using Hash Tables

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.

Attachments hashTable.cpp (4.54KB) hashTable.h (0.6KB) spellcheck.cpp (1.85KB) wordlist.txt (609.29KB) input.txt (0.2KB)
Daria Shmaria
Light Poster
25 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

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.

Stinomus
Junior Poster
110 posts since May 2009
Reputation Points: 58
Solved Threads: 17
 

> 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.

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

Thank you both very much! You helped a lot.

Daria Shmaria
Light Poster
25 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You