I'm trying to assign a pointer to a pointer within a function. I've passed pointers in and I'm trying to make the change inside. It is not happening, however. The issue is regarding the insert function, which I've played around with and have no clue how to fix.
Here's the relevant code: -> All of it is here.
void insert (struct linkedList *newElement, struct linkedList *arrayAreaHeader) {
if (arrayAreaHeader == NULL) {
arrayAreaHeader = malloc(sizeof(list));
arrayAreaHeader = newElement;
eprintf("your new element has become the first array \n");
} else {
// check if NEXT is free, recursively; how do I do that? -> then I can assign the pointer value of Element to NEXT! ALT: add as head and make changes... faster as well!
for (list *temp = arrayAreaHeader; temp != NULL; temp = temp->next) {
if (temp->next == NULL) {
temp->next = newElement; break;
}
}
}
}
int main () {
// TODO
list *myDict[26] = { NULL };
FILE *file = fopen("small", "r");
if (file == NULL)
{
fprintf(stderr, "ah darn");
}
char tempWord[30];
fscanf(file, "%s", tempWord);
eprintf("%s first\n", tempWord);
list *newElement = create(tempWord);
eprintf("%s\n", newElement->word);
int numero = hash(tempWord);
eprintf("do we get this far? \n");
insert(newElement, myDict[numero]);
eprintf("yo we made it: %s\n", myDict[numero]->word);
fclose(file);
}