I have a binary file in CSV format that contains multiple records. Each record is entered in as user_name, last_name, first_name, num_wins, num_losses, num_ties. I am creating a method to update a certain players record of wins,losses and ties. The user inputs the username to change followed by the changes to the wins, losses and ties. For example smithj 4 5 1. This will find the smithj record and add 4 to the wins etc.
How do I use lseek or fseek to accomplish this? Or is there another way to do this?
Response to request for write-up of example – assuming fixed size records:
Repeat the code from the declaration of
recnumto the end once for each record that must be modified (think loop).With variable size records that change size as you edit them, you have to work a lot harder – so much so that it is probably simpler to copy the old file into memory one record at a time, modifying the record appropriately, and then writing the modified record to a new file.