I'm new with C.
I writing simple linked list application.
this is my code :
typedef struct
{
struct node * NextNode;
int data;
}node;
void addNode(int data, node * Head)
{
if (Head == NULL)
{
Head = malloc(sizeof(node));
Head->data = data;
Head->NextNode = NULL;
return;
}
node* CurrentNode = Head;
node* _Newnode = malloc(sizeof(node));
(*_Newnode).data = data;
_Newnode->NextNode = NULL;
while (CurrentNode->NextNode != NULL)
{
CurrentNode = CurrentNode->NextNode;
}
CurrentNode->NextNode = _Newnode;
}
The problem rise is when passing Head = NULL
after passing head= NULL
,the Head
didn't change and remained NULL
What am I doing wrong ?
can you please also explain what is happening underneath ?
thanks