I have created a linked list struct in c
struct node{
int value;
struct node* next;
};
a method to add a node at the start of the list :
the node pointer could not be changed into the function in this way. in the function you are able to change the content of the pointer and not the address of the pointer. To do you have to pass your pointer of pointer struct node **list
here after how to do it:
void addFirst(struct node **list, int value){
struct node *new_node = (struct node*) malloc (sizeof (struct node));
new_node->value = value;
new_node->next = *list;
*list = new_node;
}
or you can do it in this way
struct node * addFirst(struct node *list, int value){
struct node *new_node = (struct node*) malloc (sizeof (struct node));
new_node->value = value;
new_node->next = list;
return new_node;
}
and in your cod you can get the head after the call of this function
head = addfirst(head,45);