Hello,
I am writing a simple linked list implementation program... But im facing a problem in printing the contents of list, here is the code..
Code:
#include<stdio.h>
void insert(int value);
int delete();
void showList();
struct node
{
int data;
struct node *nextNode;
};
//start pointer node
struct node *start = NULL;
int main()
{
int c=0,value;
printf("\nThis Program demonstrates simple Linked List\n");
while(c != 4)
{
printf("Choices:\n");
printf("Press 1 to insert into Linked List\n");
printf("Press 2 to delete from Linked List\n");
printf("Press 3 to display Linked List\n");
printf("Press to quit\n");
scanf("%d",&c);
switch(c)
{
case 1:
printf("\n Enter Value that you want to insert:\n");
scanf("%d",&value);
insert(value);
break;
case 2:
printf("\n Deleting first element from List:\n");
printf("\n%d \n", delete());
break;
case 3:
printf("\n Linked List:\n");
break;
case 4:
printf("\nQuitting.....\n");
exit(0);
default:
printf("\nNot a valid choice..\n");
}
}
return 0;
}
void insert(int value)
{
struct node *n;
n = (struct node *)malloc(sizeof(struct node));
n->data = value;
if(start == NULL)
{
printf("start null\n");
start = n;
n->nextNode = NULL;
}
else
{
n->nextNode = start;
start = n;
}
}
int delete()
{
return 0;
}
//this portion is creating problem...
void showList()
{
struct node *t;
t = start;
while(t!= NULL)
{
printf("%d , ",t->data);
t = t->nextNode;
}
}
Whenever i choose 3, that is list the contents of list.. it shows blank..
I don't understand where is the fault..