Floating Point Exception Using Hash Tables

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 25
Reputation: Daria Shmaria is an unknown quantity at this point 
Solved Threads: 0
Daria Shmaria Daria Shmaria is offline Offline
Light Poster

Floating Point Exception Using Hash Tables

 
0
  #1
May 22nd, 2009
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.
Attached Files
File Type: cpp hashTable.cpp (4.5 KB, 5 views)
File Type: h hashTable.h (612 Bytes, 4 views)
File Type: cpp spellcheck.cpp (1.9 KB, 3 views)
File Type: txt wordlist.txt (609.3 KB, 3 views)
File Type: txt input.txt (208 Bytes, 3 views)
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 109
Reputation: Stinomus is on a distinguished road 
Solved Threads: 16
Stinomus Stinomus is offline Offline
Junior Poster

Re: Floating Point Exception Using Hash Tables

 
0
  #2
May 22nd, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Floating Point Exception Using Hash Tables

 
0
  #3
May 22nd, 2009
> 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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 25
Reputation: Daria Shmaria is an unknown quantity at this point 
Solved Threads: 0
Daria Shmaria Daria Shmaria is offline Offline
Light Poster

Re: Floating Point Exception Using Hash Tables

 
0
  #4
May 24th, 2009
Thank you both very much! You helped a lot.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC