0

Hi,

I am creating a hash table which is basically a pointer array of 6151 elements. I use it for chaining. But my code doesnt work properly. There's an error at T=NULL and at function call. This is how it goes:

#include <iostream>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

typedef struct Node *Node_ptr;

struct Node
{
        string k;        //key k
        int i;                //value i
        Node_ptr next;        //pointer p
};

typedef Node_ptr LIST;
LIST T[6151];

void Chained_Hash_init(LIST T)
{
        for(int i=0;i<6151;i++)
          T[i]=NULL;  <----- Error in compilation shown here
}

void createMTable() //this function is 100% correct
{
        vector<string> MTable;
        string s,line;
        int pos;
        ifstream fin;
        fin.open("dict.txt");
        while(getline(fin,line))
        {
                pos=line.find('\t');
                pos=pos+1;
                s=line.substr(pos);
                MTable.push_back(s);
        }
        cout << MTable[1] << endl;
        cout << MTable[2] << endl;
        cout << MTable.size() << endl;
        fin.close();
}


int main()
{
        createTable();
        Chained_Hash_init(T);  <----- Error in compilation shown here
        return 0;
}

Can anyone please help?
Thanks!

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by xyzt
0

your definition is local in the function 'createMTable' at line 28:
vector<string> MTable;
you fill the vector but it's destructed at the end of the function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.