I am trying to implement a linked list in C. Here is my definition of a Node structure, followed by a function for adding a Node to the end of the linked list.
struct Node{
char *name;
struct Node *next;
};
typedef struct Node Node;
void addNode(Node *head, char n[100]){
if(head->next == NULL){
Node new;
new.name = n;
new.next = NULL;
head->next = &new;
}
else{
addNode(head->next, n);
}
}
I can create a head node and pass a pointer for it into the addNode function just fine to add a second node to the linked list. (Also worth mentioning that when I make a head node, I set its "next" pointer to NULL to represent the end of the linked list) The problem seems to be with the recursive call to addNode in the else branch of the addNode function, as my program works without crashing when I comment it out. Why is this causing my program to crash, and how can I fix it?