Alex Rivera | Logout

C file streams, inserting at the beginning

Asked 2011-01-10T22:53:54.997
11

Is there a simple way to insert something at the beginning of a text file using file streams? Because the only way I can think of, is to load a file into a buffer, write text-to-append and then write the buffer. I want to know if it is possible to do it without my buffer.

Edit
Report

1 Answer

7

There is no simple way, because the actual operation is not simple. When the file is stored on the disk, there are no empty available bytes before the beginning of the file, so you can't just put data there. There isn't an ideal generic solution to this -- usually, it means copying all of the rest of the data to move it to make room.

Thus, C makes you decide how you want to solve that problem.

answered 2011-01-11T00:17:26.690

Your Answer