I have a function here that destroys an iterator acting on a sorted list.
void SortedListDestroyTheIterator (SortedListIteratorPtr iter)
{
Node pt = NULL;
Node prev = NULL;
SortedListIteratorPtr walk;
walk = malloc(sizeof(struct SortedListIterator)+1);
SortedListPtr li = iter->list;
for(pt = li->start; pt!=NULL; pt = pt->next) //problem line of code
{
walk = pt->info;
//delete
if(walk==iter){
if(prev==NULL){
li->start = li->start->next;
}
else
{
prev->next = pt->next;
}
}
prev = pt;
}
free(iter);
}
I have figured out that a segmentation fault occurs with this assignment statement: pt = li->start. Now this line of code is creating a node that points to the starting node of the list. If I type in li->start it works, but once I add the assignment pt=li->start I get a segmentation fault. I do not understand why or how to fix this.