P
parthaspanda22
How can I get to discard the contents of a text file from a specified
offset(
say, obtained from ftell)?
Sincerely.
offset(
say, obtained from ftell)?
Sincerely.
How can I get to discard the contents of a text file from a specified
offset( say, obtained from ftell)?
Sincerely.
How can I get to discard the contents of a text file from a specified
offset(
say, obtained from ftell)?
How can I get to discard the contents of a text file from a specified
offset( say, obtained from ftell)?
How can I get to discard the contents of a text file from a specified
offset(
say, obtained from ftell)?
Richard Heathfield said:(e-mail address removed) said:
If you just mean that you don't want to read any more from
that file, then don't read any more from that file.
If you want to delete the contents of the file from a
specified point onwards, there is no standard function to
do that (although implementation-specific functions are
sometimes provided by library implementors), but there is
a standard *technique* to do it, which is very simple:
* open the existing file for input
* open a new file for output
* if both those operations succeeded
* read from input all the data you want to keep,
and write it to the output (checking, of course,
that both reading and writing proceed correctly)
* close both files, checking that these operations
succeeded
* if all is still well
* delete the old file using remove()
* rename() the new file so that it takes the old name
That's it. Since this operation destroys data unrecoverably,
make sure at every step that all is well before proceeding
to the next step. Remember that, right up until the remove()
call, it's still possible to change your mind. After that,
you have no (standard) way to recover the data.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.