Hi there,
I am doing some coursework in which I have to create a basic hash table. I am just experimenting at the moment, but I have made the hash function and as my hashtable, I want to have an array of the following Hashrow struct:
Code:
typedef struct l {
char *data;
struct l *next;
} List;
typedef struct h {
List l;
} Hashrow;
So basically when I initialise my hashtable, it is just an array of my Hashrow elements.
So first I put a sample word through my hash function which returns a hash address. Then I send the word, the hash address (index of hash table) and a pointer to my hash table up to my insertword() function:
Code:
Hashrow *insertword(char *key, int hashaddress, Hashrow *hashtable) {
hashtable[hashaddress].l.data = key;
return hashtable;
}
I have tested to see if the word has been added and it has. Cool!
My problem is that I want to be able to check the 'data' member of the list at a certain index of the hash table, and if nothing has been added then fine that's all I want to know. I thought I could do this by something like:
Code:
char *blah = hashtable[11].l.data;
if(blah == NULL)
printf("nothing there");
but it doesn't work.
As the 'data' member is a pointer to char, then it is an address which has not be assigned yet (erm.. I think). Do I need to initialise all the data members of my lists when initialising the hash table?
I could do with finding out what the value of the uninitialsied is so that I can make an 'if(blah == blah)' test to check that there is nothing in that index of the hash table.
This is so that I can decide whether toadd the word directly or whether I need to create another List element for direct chaining.
I hope I've made sense. If I could learn just one thing from a reply, then it would be what is the unititialised value of char *data.
Many thanks
Joe