PLZ HELP TO GET THE OUTPUT FOR THIS PROGRAM

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

struct node{
int data;
struct node *next;
};

void insert(struct node *h)
{
struct node *t,l;
int d;
t=(struct node
)malloc(sizeof(struct node));
printf(“enter the vlue”);
scanf("%d",&d);
if(h==NULL)
{
t->data=d;
t->next=NULL;
h=t;
l=t;
}
else
{
l->next=t;
t->data=d;
t->next=NULL;
}
}
void display(struct node *h)
{
while(h!=NULL)
{
printf("%5d “,h->data);
h=h->next;
}
}
int main()
{
struct node *h=NULL;
char m;
while(1)
{
clrscr();
printf(”\n 1.insert");
printf("\n 2.display");
printf("\nenter 3 for exit");
printf("\nenter choice");
scanf("%c",&m);
switch(m)
{
case ‘1’:insert(h);
break;
case ‘2’:display(h);
break;
case ‘3’:return(0);
}

getch();
}
}

This is a discussion forum,not a compiler. Please explain what kind of help u need.

1 Like

Get the Output !! what is this program about ??at least be reasonable to give details as to what you want out of this program, if you just want output, type printf("Output"); and thats the best answer you can get.

There are many basic errors in your program, you have used malloc in your program but never included the header file #include<malloc.h> . and many others , which shows you haven’t run this program yourself for once or even tried to debug it.

@abhigoud: there are so many errors in your code. h,l,t are pointers to your struct node but you declared them as struct nodes instead of struct node *h and then you are changing position of ‘h’ it is not pointing to your first node for displaying purpose, so keep a pointer at the beginning of your node for displaying. and no need of #include<conio.h> and clrscr();

1 Like
//