Hello,
Thank you for taking the time to read this. I am writing a function that will replace a user-entered value in a list. It will replace every single instance of that value with a new value. My problem is my program changes every user-entered value successfully except if that # is the last one in the list.
I will post the 2 functions it depends on here because I think that's where the error is. The rest of the files including lab3.c containing main() are attachments to this thread. So here it is...
Code:
Position Find( ElementType X, List L, Position P )
{
while( P != NULL && P->Element != X )
P = P->Next;
return P;
Replace(ElementType old_val, ElementType new_val, List L)
{
Position P = L->Next; // initialize Position to first position of list
do {
P = Find(old_val, L, P); // find a position of the value to replace
// search from the value after the one replaced
P->Element = new_val; // replace old value with a new value
P = P->Next; // skip a spot to find other instances of same value
}while (P != NULL ); // test if the next spot is a NULL and hence end of list
}
Note: the file containing main() is lab3.c
I appreciate your time in taking a look at this. It really means a lot to me.
Yev