0

I've been working very long on this and I can't find a way out. I've created a node struct and a hash struct. Like this:

typedef struct node { char value[45]; struct node* next; }node; typedef struct hash { int count; struct node* head; }hash;

My dictionary consists of an array of 26 hash structs. The array is called alfabet and I've created a global pointer to alfabet (hash *alfabet). Then I mallocced 26 structs for it inside my load function. I have a separate function that returns a node. This node is equal to temp. When I insert nodes in a hash struct I do the following:

if (!alfabet[letter].head) { alfabet[letter].head = temp; alfabet[letter].count = 1; }else { temp -> next = alfabet[letter].head; alfabet[letter].head = temp; alfabet[letter].count++; }

My first question is: is the head now pointing to temp or is it being replaced by temp? Is that causing my problem? I'm using a space reserved for a hash struct and pushing a node inside? This does produce a nice looking hash table but my checker doesn't work. I've made a cursor from a hash struct and from a node struct. Hash works a little bit better. It looks like this:

struct node *cursor = alfabet[teller].head or struct hash *cursor = &alfabet[teller]

But it doesn't work. I try to get to the value of a node like this :

with the node cursor : cursor -> value with the hash cursor : cursor -> head -> value

It does work for a number of words but I run into errors. I get EMs like this.

runtime error: member access within null pointer of type 'struct node' runtime error: null pointer passed as argument 2, which is declared to never be null /usr/include/string.h:145:33: note: nonnull attribute specified here Segmentation fault

It's the same EM whether I use a node or a hash cursor. The EMs always refer to the line in which I strcmp the word from the text with the value in a node. I can't fix it. I've tried and tried and tried. Maybe I could solve this by dereferencing the value properly but I can't figure out how. I hope I've given you sufficient information. Of course I can give you lots more. Thank you.

2
  • What's the meaning of this hash struct? Does it mean you're attempting a hashmap (which is just an array of linked lists, with the index being derived from some hash)? – Blauelf Aug 4 '17 at 14:10
  • Well, I found that hash struct on the internet and somehow I never was able to get rid of it. The head pointer is handy. The index is derived from a hash function that I found in CS50 study. I copied it and it works very well. – Karin Aug 4 '17 at 14:17
0

Ok,it's not really a pointer issue. Sometimes my cursor simply equals null. I think I have to review how I read in the text I wish to check. Or my apostrophe function in which I deal with colons, comma's ... I am so sorry for all the fuss, I was very tired and my impostor syndrome played up. When that happens I refuse to stop trying and I end up writing questions like this. I'd delete it because it doesn't really share any relevant information, does it?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .