Linked List problem

This is a discussion on Linked List problem within the C Programming forums, part of the General Programming Boards category; I apologize for the non explanation. What my program is supposed to do is first read input from a file ...

IT should read one record off teh second file one at a time and look to see if it already exists on the list if so it should do a series of checks like to see if its a withdrawal or a deposit and such and such. For the most part i have every thing working fine except the part where if the person exist on the list and the amount they are trying to withdraw is larger than their current balance i delete them. The only problem i have is when i read the last name Alagappan Solayappan, he is at the top of the list (the head) i need to delete the head and i can't figure out how to do it.

All I can really say about linked lists, is to draw a picture of each record in the list and link them with lines, and go through your program changing what the tempptr or whatever is pointing at and then if you say wanna delete a record then work out what you'll be searching for and where all the pointers will be at once you find it and try to reconnect the list and delete the record without moving a pointer off of any of the records.

the reason is that bankrecords should always hold the first value in the list, otherwise your freeing the piece of memory that bankrecords is pointing too without telling bankrecords what to point to, so when you print the list again it will print nothing and the value of ->next will be screwed, etc. but in your example you were deleting the second record, not the first, the above will remove the first.
Note: if you want to use tempptr again straight after this code, you'll need to do:

Code:

tempptr = *bankrecords;

hope this helps, basically if you want to change the first value of your list always use *bankrecords, otherwise you can use tempptr.

no problems, linked lists are always tricky because you always need to account for deleting records (nodes) in the middle and at the start and making sure that everything is pointing to something, etc.