This might be a question with a very simple solution but I can't get my head around it... I'm trying to implement linked list for a school proyect using structures but when I initialize the very first node, malloc seems to make no effect at all
here's my code so far:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
typedef struct Node Node;
struct Node
{
int data;
Node *next;
};
void init_List(Node *head, int data)
{
head = (Node*)malloc(sizeof(Node));
if(head == NULL)
{
printf("Memory Allocation Error");
return;
}
head->data = data;
head->next = NULL;
}
int main()
{
Node *head = NULL;
int N;
printf("N: ");
scanf("%d", &N);
init_List(head, N);
printf("%d", head->data);
}
whatever number I read to make the first data of my node prints as cero. don't know what could be happening. thanks for the help!