Hello,
I'm trying to write a program which deletes the last element in a linked list of structures. However, I'm stuck with free, I know how it works but free() always give problems, any help?
This is my code:
Code:
/* deletes last element */
void delete_last (LINKED* *list)
{
LINKED *p;
LINKED *q;
p = *list; // initialize pntr
if (*list == NULL) // control for empty list
printf("EMPTY LIST.\n");
else if ((*list)->pntr == NULL) // control for 1 element
free((*list)->pntr);
else
{
while (p->pntr != NULL)
{
q = p;
p = p->pntr;
}
free(q);
q = NULL;
}
}