i am facing problem when i am trying to get input...my input is not being taken correctly ...
#include<stdio.h>
struct student
{
char name[20];
int rollno;
struct student *next;
};
void display(struct student *first)
{
struct student *ptr;
ptr=first;
printf("\nCurrent list:\n");
while(ptr!=NULL)
{
printf("Name:%s\nRoll:%d",ptr->name,ptr->rollno);
ptr=ptr->next;
}
}
void delet(struct student *first,int 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);
switch(choice)
{
case 1:
printf("\nEnter the no of students you want to add:");
scanf("%d",&n);
first=newstudent;
printf("\nEnter the name:");
gets(first->name);
printf("\nEnter roll no:");
scanf("%d",first->rollno);
first->next=NULL;
last=first;
for(i=1;i<n;i++)
{
x=newstudent;
printf("Enter your name:");
gets(first->name);
printf("Enter your rollno:");
scanf("%d",&first->rollno);
x->next=NULL;
last->next=NULL;
last=x;
}
break;
case 2:
if(first!=NULL)
{
printf("\nEnter the roll:");
scanf("%d",&val);
delet(first,val);
display(first);
}
else
{
printf("List is Empty");
}
break;
case 3:
if(first!=NULL)
{
display(first);
}
else
{
printf("List is empty");
}
break;
case 4:
exit(0);
break;
}
}while(choice!=4);
return(0);
}