This functions receives the linked list as a parameter and has to delete the node of the list which element DNI coincides with the string given to get_string and then return the list. At the moment the function works well if the node given is the first one but if the node given is any but the first it always removes the first element and messes up the list. What should I do to fix it?
PPACIENTE p_discharge(PPACIENTE pac){
char dni[10];
int u, c=0;
PPACIENTE pAux;
PPACIENTE temp;
pAux=pac;
fprintf(stdout,"Discharge\n\n");
if (pac==NULL)
{
printf("No patients yet\n");
}
else
{
get_string("DNI",9,9,dni);
while(pAux!=NULL){
if(strcmp(pAux->DNI,dni)==0) {
u=1;
break;
}
else{
pAux=pAux->sig;
}
}
if (u==1){
if (pAux->num==1)
{
pac=pAux->sig;
free(pAux);
return pac;
}
else
{
printf("%d\n", pAux->num);
c=pAux->num;
while(pAux->num!=(c-2))
pAux=pAux->sig;
temp=pAux->sig;
pAux->sig=temp->sig;
free(temp);
}
}
else{
printf("Unknown patient\n");
}
}
return pAux;
}