PLZ HELP ME WITH THIS CODE...I HAVE GIVEN THIS CODE SO MANY TIMES BUT NOBODY IS ABLE TO CLEAR MY ERROR....
1.DISPLAY IS NOT COMING ONLY LAST VALUE I ENTER IS DISPLAYED
2.DELETION OPETATION
.............AND YES I WANT TO USE LINKED LIST....IF ANY 1 KNOWS IT TELL ME.............
#include<stdio.h>
struct student
{
char name[20];
char rollno[20];
struct student *next;
};
void display(struct student *newstudent,int n)
{
int i;
for(i=0;i<n;i++)
{
printf("\nCurrent list\n");
while(newstudent!=NULL)
{
printf("Name:%s\nRoll:%d",newstudent->name,newstudent->rollno);
newstudent=newstudent->next;
}
}}
void delet(struct student *first,char val)
{
struct student *ptr,*list ;
ptr=first;
while(ptr!=NULL)
{
if(ptr->rollno==val)
{
list=ptr;
ptr=ptr->next;
free(list);
}
}
}
int main()
{
struct student *first,*last,*x,*newstudent;
first=last=NULL;
int c=0,val,choice,i,n;
do
{
printf("\n\n\tMenu linked list\n");
printf("1.Create\n2.Delete\n3.Display\n4.Exit\n");
printf("\nEnter your choice:");
scanf("%d",&choice);
getchar();
switch(choice)
{
case 1:
printf("\nEnter the no of students you want to add:");
scanf("%d",&n);
getchar();
for(i=0;i<n;i++)
{
newstudent=(struct student*)malloc(sizeof(struct student));
printf("\nEnter the name:");
gets(newstudent->name);
printf("\nEnter roll no:");
gets(newstudent->rollno);
newstudent->next=NULL;
if(first==NULL)
{
first=newstudent;
}
else
{
struct student *temp=first;
while(temp->next!=NULL)
temp=temp->next;
temp->next=newstudent;
}
}
break;
case 2:
if(first!=NULL)
{
printf("\nEnter the roll:");
scanf("%d",&val);
delet(first,val);
display(newstudent,n);
}
else
{
printf("List is Empty");
}
break;
case 3:
if(newstudent!=NULL)
{
display(newstudent,n);
}
else
{
printf("List is empty");
}
break;
case 4:
exit(0);
break;
}
}while(choice!=4);
return(0);
}