Help me out in this deletion operation

It is my earlier program and i just modified it but now i am not being able to perform deletion operation..if you will help me my project will get over..

[code]
#include
struct student
{
char name[20];
int rollno;
int physics;
int chemistry;
int biology;
int maths;
int IP;
int total;
float percentage;
struct student *next;
};
void display(struct student *head,int n)
{
struct student *temp=head;
printf("
Current list
");
while(temp!=NULL)
{
printf("
Name:%s
Roll:%d
Physics:%d
Chemistry:%d
Biology:%d
Maths:%d
IP:%d
",temp->name,temp->rollno,temp->physics,temp->chemistry,temp->biology,temp->maths,temp->IP);
printf("Total:%d",temp->total);
printf("
Percentage:%f",temp->percentage);
if(temp->percentage<=45)
{
printf("
You just failed");
}
else
{
printf("
You passed");
}
temp=temp->next;
}
}
void delet(struct student *first,int val)
{
struct student *ptr,*temp;
ptr=first;
while(ptr!=NULL)
{
if(ptr->rollno==val)
{
temp=ptr;
ptr=ptr->next;
free(temp);
}
else
{
printf("The roll no does not exists");
}
}


int main()
{
struct student *first,*last,*x,*newstudent;
first=last=NULL;
int c=0,val,choice,i,n;
do
{
printf("

Menu linked list
");
printf("1.Create
2.Delete
3.Display
4.Exit
");
printf("
Enter your choice:");
scanf("%d",&choice);
getchar();
switch(choice)
{
case 1:
printf("
Enter the no of students you want to add:");
scanf("%d",&n);
getchar();
for(i=0;iname);
printf("
Enter roll no:");
scanf("%d",&newstudent->rollno);
getchar();
printf("
Enter the student marks");
printf("
Enter physics,chemistry,biology,maths,IP marks:");
scanf("%d%d%d%d%d",&newstudent->physics,&newstudent->chemistry,&newstudent->biology,&newstudent->maths,&newstudent->IP);
getchar();
newstudent->total=newstudent->physics+newstudent->chemistry+newstudent->biology+newstudent->maths+newstudent->IP;
newstudent->percentage=newstudent->total/5;
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("
Enter the roll:");
scanf("%d",&val);
delet(first,val);
display(first,n);
}
else
{
printf("List is Empty");
}
break;
case 3:
if(first!=NULL)
{
display(first,n);
}
else
{
printf("List is empty");
}
break;
case 4:
exit(0);
break;
}
}while(choice!=4);
return(0);
}
[/ICODE]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories