I am trying to learn linked list and getting syntax error in following code which i not able to figure out
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct node
{
struct node *prev;
int data;
struct node *next;
};
struct node* append(struct node**,int);
struct node* addAtBegining(struct node**,int);
//struct node* addAfter(struct node*,int,int);
struct node* delete(struct node**,int);//Syntax error
void desplay(struct node*);
void main()
{
struct node *value,*current,*start;
int noOfItems,item,location;
printf("\nEnter No Of Intems You want To Enter\n");
scanf("%d",&noOfItems);
value=NULL;
for(int counter=0;counter<noOfItems;counter++)
{
printf("\nEnter The Item\n");
scanf("%d",&item);
current=append(&value,item);
if(counter==0)
{
start=current;
}
}
/*printf("\nEnter A Item At Beginning\n");
scanf("%d",&item);
current=addAtBegining(&value,item);
start=current;
printf("\nEnter A Item\n");
scanf("%d",&item);
printf("\n");
printf("\nEnter A Location\n");
scanf("%d",&location);
start=addAfter(value,item,location);
printf("\nstart=%u",start);*/
desplay(start);
}
struct node* append(struct node **s,int num)
{
struct node *r,*start;
if(*s==NULL)
{
*s=(struct node*)malloc(sizeof(node));
start=*s;
(*s)->prev=NULL;
(*s)->data=num;
(*s)->next=NULL;
start=*s;
}
else
{
while((*s)->next!=NULL)
{
(*s)=(*s)->next;
}
r=(struct node*)malloc(sizeof(node));
r->prev=*s;
r->data=num;
r->next=NULL;
(*s)->next=r;
}
return start;
}
struct node* addAtBegining(struct node **s,int num)
{
struct node *r;
r=(struct node*)malloc(sizeof(node));
r->prev=NULL;
r->data=num;
r->next=*s;
*s=r;
return *s;
}
/*struct node* addAfter(struct node *s,int num,int loc)
{
struct node *temp,*start;
start=s;
for(int counter=1;counter<=loc;counter++)
{
s=s->next;
if(s==NULL)
{
printf("\n%d Location Does Not Exists\n",loc);
}
}
s=s->prev;
temp=(struct node*)malloc(sizeof(node));
temp->prev=s;
temp->data=num;
temp->next=s->next;
temp->next->prev=temp;
temp->prev=s;
return start;
}*/
struct node* delete(struct node **start,int num)//Syntax error
{
struct node *variable;
variable=*start;
while(variable!=NULL)
{
if(variable->data==num)
{
if(variable==*start)
{
*start=(*start)->next;
(*start)->prev=NULL;
}
else
{
if(variable->next==NULL)
{
variable->prev->next=NULL;
}
else
{
variable->prev->next=variable->next;
variable->next->prev=variable->prev;
}
}
}
free(variable);
variable=variable->next;
}
}
void desplay(struct node *variable)
{
printf("\nstart=%u",variable);
if(variable==NULL)
{
printf("\nNothing To Display,Linked List Is Empty\n");
}
else
{
while(variable!=NULL)
{
printf("Item%d\n",variable->data);
variable=variable->next;
}
}
getch();
}
Kindly help me.
Thanks in advance.