I've got a project that requires the user to input a capacitor's ID and its corresponding capacitance. The user can add the capacitor at the beginning or end of the list. But, I'm having trouble figuring out how to put it at the end of the list.
while( currentPtr != NULL)
{
//Validate there aren't duplicate identifiers
if (newPtr -> capacitor_id == currentPtr -> capacitor_id)
{
fprintf(stderr, "ID USED: Capacitors must have unique identification numbers.");
return; //Silent return to main
}
currentPtr = currentPtr -> next; //Move to the next ptr
}
currentPtr = newPtr;
The while loop loops through the existing linked list until it reaches the end of the list which has a dummy NULL value. This works as expected but it does not add the capacitor to the list.
Note:
--newPtr is a pointer that points to the structure capacitor. It holds both the ID and capacitance.
Any ideas would be greatly appreciated! :)
Thanks!