So. I am trying to make a program that just stores strings in a file. I haven’t actually implemented any of it yet, but I have encountered a problem. There is a point in the program where I want to replace a string in a file, but what if the string I am replacing is longer than the string I am replacing it with? **So I was wondering if there is a way to erase characters/bytes instead of simply overwriting them in a file?** I’ve thought of a way to avoid this that would just be overwriting the non-overwritten bytes/chars with '\0' and then just trim them, but I would rather find a better way.
tl;dr : **I was wondering if there is a way to erase characters/bytes instead of simply overwriting them in a file?**
Basically if the complete file contents are small enough to fit in memory, just make the changes in memory, "remove" the file contents then rewrite the file. Otherwise you will need to create a new file that contains the changes and then delete the file and replace it with the newly written file.