You pretty much can't do this.
You can use fseek
to go to a specific location in a file, and you can write data to that location (you probably want to use "r+"
mode).
But a file is typically stored as a sequence of bytes (or characters), not as a sequence of lines.
If you're careful to write exactly the same number of bytes that were already in the line, you can probably get away with it -- but in your example, the lines are of varying lengths, so this isn't an option.
You could, for example, pad each line with blanks, so they're all the same length, but then it's easy to corrupt the layout if you modify the file using, say, an ordinary text editor.
For text files, the usual approach is to read the file into memory, modify the in-memory representation, and then re-create the entire file. You probably want to write the contents to a new temporary file, then rename it after you've confirmed that there were no write errors.
This is what text editors typically do.
(Don't worry too much about efficiency; 2000 lines isn't all that big, and you won't notice the time it takes to write them.)
There are alternatives. You can define a binary format with fixed-length records, or you can use a database. Or you can just append new lines to the file, and treat duplicates as if they had been deleted (but this can cause the file to grow very large if you do a lot of updates).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…