I'm trying to make a linked list, but my head seems to be staying eternally null. I defined a node struct and my head
Code:
typedef struct node_s
{
int id;
data_t data;
struct node_s *next;
} node_t;
node_t *headNode = NULL;
I created an insert function that should allow for inserting id and data into any list
Code:
void insert(int id, data_t data, node_t **head)
{
node_t *cur = NULL;
nodeDup(cur, *head);
//find where to insert
if(cur == NULL)
{
*head = (node_t *)malloc(sizeof(node_t));
//assign values
}
}
void nodeDup(node_t *v1, node_t *v2)
{
if(v2 == NULL)
return;
v1 = (node_t *)malloc(sizeof(node_t));
v1->id = v2->id;
//etc
}
int main()
{
...
insert(1, data, &headNode);
insert(2, data, &headNode);
...
}
cur is always null, even in successive calls to insert. Shouldn't "*head = (node_t *)malloc(sizeof(node_t));" be causing headNode to no longer be null?