But my delete function is causing issues. I can delete the LAST member of the list, but whenever I try and delete any other member, I get this error:
"Access violation reading location 0xfeeefeee."
I'm guessing that means one of my pointers is screwed up. I've played around with it for a few hours but can't get past this point.
It breaks on this line:
printf( " <-- %c", currentPtr->data );
which is in my print backwards function.
The whole function is:
void printBackwards ( ListNodePtr currentPtr )
{
ListNodePtr temp = NULL;
while ( currentPtr != NULL ) {
temp = currentPtr;
currentPtr = currentPtr->nextPtr;
}
printf( "\nReverse List:\n" );
printf( "NULL" );
currentPtr = temp;
while ( currentPtr != NULL) {
printf( " <-- %c", currentPtr->data );
currentPtr = currentPtr->prevPtr;
}
printf("\n\n");
}
Here is my delete function:
/* delete a list element */
char charDelete ( ListNodePtr *sPtr, char value )
{
ListNodePtr previousPtr; /* pointer to previous node on list */
ListNodePtr currentPtr; /* pointer to current node on list */
ListNodePtr tempPtr; /* temperary node pointer */
/* delete first node */
if (value == ( *sPtr )->data)
{
tempPtr = *sPtr; /* hold onto node being removed */
*sPtr = ( *sPtr )->nextPtr; /* de-thread the node */
free( tempPtr ); /* free the de-threaded node */
return value;
}
/* end if */
else
{
previousPtr = *sPtr;
currentPtr = ( *sPtr )->nextPtr;
/* loop to find correct location on list */
while ( currentPtr != NULL && currentPtr->data != value ) {
previousPtr = currentPtr; /* walk to ....*/
currentPtr = currentPtr->nextPtr; /*....next node*/
} /* end while */
/* delete node at currentPtr */
if ( currentPtr != NULL )
{
tempPtr = currentPtr;
previousPtr->nextPtr = currentPtr->nextPtr;
free ( tempPtr );
return value;
} /* end if */
} /* end else */
return '\0';
} /* end function delete */
Everything looks ok. I don't see anything wrong with my logic. Could it be my compiler?
Thanks

New Topic/Question
Reply



MultiQuote






|