I'm fairly certain this has something to do with pointers and the function using copies instead, but I'm not sure how...because I've inserted the pointer as a parameter for create();
#include <stdio.h>
#include <cs50.h>
#include <string.h>
typedef struct list {
string word;
struct list *next;
}
linkedList;
struct list* create (string newWord) {
linkedList *new = malloc(sizeof(newWord));
new->word = newWord;
new->next = NULL;
return new;
}
struct list* insert (struct list *theList, string newValue) {
linkedList *anotherOne = create(newValue);
anotherOne->next = theList;
return anotherOne;
}
int hash (string name) {
return strlen(name);
}
void hashInsert (struct list *theList, string newValue) {
theList = create(newValue);
}
int main(void) {
linkedList *names[24] = {NULL};
int num = hash("heey");
// names[num] = create("heey"); // <- this code works when I uncomment it
hashInsert(names[num], "heey"); // <-- this causes a segfault.. idk why
printf("%s", names[num]->word);
}