There are many similar questions, but nothing that answers this specifically after a multiplayer game. Here:
Let's say we have a file (maybe binary and much more):
abcdefghijklmnopqrztuvwxyz
What is the best way in C to "move" the right most of this file to the left, truncating the beginning of the file .. so, for example, "truncating the front" of 7 bytes will change the file on disk to be:
hijklmnopqrztuvwxyz
I should avoid temporary files and prefer not to use a large buffer to read the entire file in memory. One of the possible methods that I was thinking about is to use fopen with the "rb +" flag and constantly read and write read and write to copy bytes, starting from the offset to the beginning, and then trim setEndOfFile at the end. It seems like a lot (possibly inefficient).
Another way would be to open the same file twice and use fgetc and fputc with the corresponding file pointers. Is it possible?
If there are other ways, I would love to read them all.
source share