# Thread: Help on circular list!

1. ## Help on circular list!

Pleas i need help to fix a function which seems to be wrong! it must delete a node of a circular list.

Code:
```static int rem_plan_rec(char *aname, plan_t **agende, int left) {
plan_t *tmp;
int i=0;
ec_null1( *agende, EINVAL )
if (left==0) return 1;
if (strncmp((*agende)->aname, aname, LAGENDA+1)==0) {
if ((*agende)->many!=0)	//in this case can't be deleted
return 2;
tmp=(*agende)->nxt;
(*agende)->nxt=NULL;
free((*agende));
*agende=tmp;
if (--plan_elems==1) <----- MY PROBLEM!
tmp->nxt=tmp;
else if (plan_elems>1) {
while (i++<plan_elems-1) tmp=tmp->nxt;	/*	fa si che la lista resti circolare	*/
tmp->nxt=(*agende);
}
return 0;
}
else {
agende=&((*agende)->nxt);
return rem_plan_rec(aname, agende, --left);
}
}

//the list
typedef struct plan_t {
/* Nome dell'agenda (=nome file) */
char aname[LAGENDA+1];
/* Puntatore alla lista degli eventi */
elem_t *events;
/* Numero di eventi totali */
unsigned int many;
/* Puntatore all'agenda successiva */
struct plan_t *nxt;
}
plan_t;```
plan_elems is an integer value that indicates how many nodes the list has. I Use the parameter left to know when the list is finished cause it's circular.
My problem is, as i indicated in the code, that when there are only two nodes, and one of them is deleted, the other one seems to be not connected to itself!

Cheers

2. where in the code is plan_elems declared / defined?? and maybe use that criteria for the last remaining instead of the last two.

3. the other one seems to be not connected to itself!
I don't see anything obvious in your code, what are the concrete observation leading to your problem? another function is failing? As requested in the previous post, additional code may help.