How to append a character starting from the end of a file

Apr 29, 2011 at 6:25am
Does anyone know if its possible to open a file for appending but then I need to be able to replace the last character written to the file with another. How can I advance the pointer going backwards towards the start of the file and write to each character that I would like to change ? I am also closing the file after each write or a single character then opening it with the append mode set.

Thanks

Victor
Apr 29, 2011 at 6:37am

It would be good if you read the whole file in memory, change/replace whatever you want and than again write back to the file.
Opening the file for each character is going to be very slow operation.
Apr 29, 2011 at 8:31am
The problem occurs if the whole file is very big like some server log files their filesize can reach a few Gbs.
Apr 29, 2011 at 10:19am
memory mapped files can be used. the mmap() function. I think that would work.
Last edited on Apr 29, 2011 at 10:20am
Apr 29, 2011 at 4:53pm
Thanks for all the suggestions I will take a look at the available options. Appreciate the reply. Victor.
Topic archived. No new replies allowed.