I'am trying to implement hash table with linked list, as a dictionary. but when I print the word's after the insertion, all the places have the last word on the list.

thank you for the help.

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

typedef struct node
    char* pword;
    struct node* next;

[mod: edit out extra code]


You have a very basic mistake in your logic. If you are going to use a hash table to solve this pset, your struct should include an array of chars as string, not just a pointer to string. Because when you change the temp contents, all the pointers pointing to this string (because all your char pointers in your struct, point to this very string) are changing too.

Your struct should be something like:

typedef struct node
    char word[LENGTH + 1];
    struct node* next;
  • That's exactly the implementation I went for and it seems to work. – Tikhon Jan 17 '17 at 6:52

You must log in to answer this question.

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