This is a simple program to insert a node and display it in a linked list bypassing the head node to the function. This is a part of a bigger program but I am unable to troubleshoot this. Each time I display the node it says the linked list is empty.
#include <stdio.h>
#include <stdlib.h>
struct nodes
{
int data;
struct nodes *next;
};
typedef struct nodes *node;
void InsertFront(node head)
{
int num;
node temp = malloc(sizeof(node));
printf("Enter The Value Of Node\n");
scanf("%d", &num);
temp->data = num;
if (head == NULL)
{
temp->next = NULL;
head = temp;
}
else
{
temp->next = head;
head = temp;
}
}
void Display(node head)
{
node q;
if (head == NULL)
{
printf("Linked List Seems To Be Empty");
}
else
{
q = head;
while (q != NULL)
{
printf("%d -> ", q->data);
q = q->next;
}
}
}
void main()
{
node head;
head = NULL;
InsertFront(head);
Display(head);
}