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!

Make next a pointer to type. Then move line 8 to line 16 and see how it works.

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.

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.