Does anyone know what an unhandled exception error is? It also gives an address of 77f85c41.
The program was given by my teacher. I was able to compile and link. As soon as I type the filename (to open fstream) I get a pop up message that tells me about the unhandled exception error and it closes the window. I made some changes from the orig. because it wouldn't compile with my compiler but I can't figure out how to get past this problem. The program is supposed to read in a text file ("phone.txt") and then place a name and phone # it in a bucket determined by the calc. Anyhow, here is the code.
Code:
#include<iostream>
#include<string>
#include<fstream.h>
using namespace std;
typedef struct phonerecord
{
string name;
string number;
phonerecord * next;
};
const int buckets = 11;
int hashfunction(string);
void display_buckets(phonerecord * [], int);
int main()
{
ifstream instream;
string Infilename;
int j;
int whichbucket;
phonerecord * latest;
string newname;
string newnumber;
phonerecord * newphonerecord;
phonerecord * hashtable[buckets];
for(j = 0; j < buckets; j++)
hashtable[j]=0; //empty
cout<<"Enter The Name Of The File With .txt Extension:"<<endl;
cout<<"For This Program Enter phone.txt"<<endl;
getline(cin, Infilename);
instream.open(Infilename.data());
for(;;)
{
getline(instream, newname);//takes in first line of document.
getline(instream, newnumber);
if (instream.eof()) break;
latest = newphonerecord;
latest -> name = newname;
latest -> number = newnumber;
//put into bucket
whichbucket = hashfunction(newname);
latest -> next = hashtable[whichbucket];
hashtable[whichbucket] = latest;
}
display_buckets(hashtable,buckets);
}
int hashfunction(string s)
{
int one, two, three;
one = s[0];
two = s[s.length()]-1;
three = (two/2)%11;
return three;
}
void display_buckets(phonerecord * hashtable[], int buckets)
{
int j;
phonerecord * aux;
for(j=0;j<buckets; j++)
{
aux = hashtable[j];
while (aux !=0)
{
cout<<aux -> name;
aux = aux -> next;
}
}
}
Thanks...