Appending text information to a text file at a certain spot without overwriting old information (C)

后端 未结 3 1073
感动是毒
感动是毒 2020-12-22 09:29

So I have a txt file that looks like this:

112 12.50 Y 15

267 7.75 N 20

382 15.50 N 45

User is prompted where he wants to insert

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-22 09:53

    steps:

    1. Create a temporary file
    2. Read each line from the source file and write to temporary file, parsing it as you go
    3. Then insert the new line after you've found the ID after which you would want the new line to be inserted
    4. write all the remaining lines from the source file
    5. delete the source file
    6. rename the temporary file to the name of the source file.
    7. celebrate!

提交回复
热议问题