Probably you are missing some operation to find the exact node as its deleting the other ones.
Here is the code to delete a node.
Code: C
node* del(node *current)
{
/***************************************************/
/***** FUNCTION FOR DELETION OF SPECIFIED NODE *****/
/***************************************************/
int rno; /* Roll number for deleting a node*/
node *newnode,*temp;
printf("\nEnter the number whose node you want to delete\n");
scanf("%d",&rno);
newnode=current;
if(current->roll_no==rno)
{
/*** Checking condition for deletion of first node ***/
newnode=current; /* Unnecessary step */
current=current->next;
free(newnode);
return(current);
}
else
{
while(newnode->next->next!=NULL)
{
/*** Checking condition for deletion of ***/
/*** all nodes except first and last node ***/
if(newnode->next->roll_no==rno)
{
temp=newnode->next;
newnode->next=newnode->next->next;
free(temp);
return(current);
}
newnode=newnode->next;
}
if(newnode->next->next==NULL && newnode->next->roll_no==rno)
{
/*** Checking condition for deletion of last node ***/
free(newnode->next->next);
newnode->next=NULL;
return(current);
}
}
printf("\nMatch not found\n");
return(current);
}
Also first node needs special care.