I have a problem with my code. I want to delete an element from a circular list and I did it but my problem is that instead of not seeing that number anymore I see a 0(zero) in the same position of the number that I deleted. Can anyone help me, please? The problem is in the DeleteElement
#include<stdio.h>
#include<stdlib.h>
struct nodo{
int info;
struct nodo *next;
};
typedef struct nodo* tlista;
int PrintList(tlista l){
if(l){
tlista pc=l;
do{
printf("%d",l->info);
l=l->next;
}while(l!=pc);
}
}
void DeleteElement(tlista l,int elem){
tlista pc=l;
do{
if(l->info==elem){
tlista k=l;
l=l->next;
free(k);
}else{
l=l->next;
}
}while(pc!=l);
}
int CreateList(tlista *l,int n){
tlista new=(tlista)malloc(sizeof(struct nodo));
if(new){
new->info=n;
if((*l)==NULL){
*l=new;
new->next=new;
}
else{
new->next=(*l)->next;
(*l)->next=new;
}return 1;
}else{return 0;}
}
int main(){
tlista l=NULL; int number;
int NumberInsideTheList; int numbertofind;
int thenumbertodelete; int i=0;
int risult;
printf("How many numbers do you want to insert = ");
scanf("%d",&number);
while(i<number){
printf("Insert a number that you want to insert into the
list \n");
scanf("%d",&NumberInsideTheList);
CreateList(&l,NumberInsideTheList);
i++;
}
printf("\n\n");
printf("number to delete = ");
scanf("%d",&thenumbertodelete);
DeleteElement(l,thenumbertodelete);
printf("\n\n");
PrintList(l);
return 0;
}
Thank you.