Can I print several lines into file without overwriting it?
The file is really huge and I have to add some lines in the middle many
times during the run of the program.
I am afraid that you can not. If you print something into the middle of
the file you can assume that you overwrite as many bytes as many you
print. In other words if you position the file to the start of a line then
you can overwrite the line, but
1. if the line printed is shorter than the line that was there then the
end of the line remains,
2. if the line printed is longer than the line that was there then the
next line (or even more lines after) are overwritten.
What you can safely do is to append data to a file, or handle a file with
fixed length records.
Read the documentation on the functions fopen, fclose, fseek, open, close,
seek, ftell, tell.
[ back to toc ]