error in displaying linked list after deletion from middle-please spot it and tell me
Code:
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node *next;
};
void main()
{
struct node *head, *tail, *temp,*s,*ptrl,*p;
int n,f,i;
char ch;
head=tail=NULL;
printf("want to enter data (y/n)\n");
scanf("%c",&ch);
if(ch=='y'||ch=='Y'){
printf("enter your data: \n");
scanf("%d",&n);
fflush(stdin);
tail=(struct node *)malloc(sizeof(struct node));
tail->data=n;
tail->next=NULL;
head=tail;
printf("\nwant to enter more data (y/n)");
scanf("%c",&ch);
fflush(stdin);
}
while(ch=='y'||ch=='Y'){
printf("\nenter your data: ");
scanf("\n%d",&n);
fflush(stdin);
temp=(struct node *)malloc(sizeof(struct node));
tail->next=temp;
temp->data=n;
temp->next=NULL;
tail=temp;
printf("\nwant to enter more data (y/n)");
scanf("\n%c",&ch);
fflush(stdin);
}
printf("\nenter the data you want to delete");
scanf("\n%d",&f);
ptrl=head;
s=head;
while(s!=NULL){
if(s->data!=f){
ptrl=s;
s=s->next;
}
else{
ptrl->next=s->next;
i=1;
}
}
p=head;
if(i==1){
printf("\nlist after deletion--->");
while(p!=NULL){
printf("%d ",p->data);
p=p->next;
}}
else{
printf("\nelement not found");
}
getch();
}
the error is after :::: " printf("\nenter the data you want to delete");"
please spot it and pull this poor man out of this misery