Delete a Line from a file in C Language

前端 未结 3 1832
故里飘歌
故里飘歌 2020-11-28 13:22

I want to delete certain lines in a file and insert certain lines in the same file based on whether certain parts of the line match a specified string. Is there a way of doi

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 14:08

    You can't easily "cut" a section of a file out in-place. You always make a temporary copy somewhere. This isn't a C thing; it's true for any language.

    You could mmap the file, and then when you find the line you want to erase, you can memcpy everything after it to the location of the start of the line. I'd question how efficient that would be; the temporary file might be quicker.

提交回复
热议问题