Re: Deleting a byte at the end of a file



In article <gh3qep$t0n$1@xxxxxxxxxxxxxxxxxxxxx>, Lorents <fdsa@xxxxx> wrote:
Gary Scott wrote:

This seems to work in CVF (note extensions)

program test

use dfwin

implicit none

open(10,file='\data.txt',position='append',form='binary')

backspace(10)
backspace(10)

endfile(10)

end

Thank you Gary, I tried it with intel compiler 9.1 under linux and it
compiled and worked! Thanks!
In my case I used a single backspace instead of two; as it is your program
will delete 2 bytes at the end of the file (it works in your example
probably because your data.txt contained a trailing end-of-line invisible
character)

Be warned - it is SERIOUSLY non-portable. That solution will not
work on any implementation that uses Unix append to implement that
positioning. However, no other solution will be much better, because
what you are trying to do makes no sense on many systems and is a
bit iffy even on many of those where it does make sense.

So always test such code every time you use it after a compiler
or system upgrade.


Regards,
Nick Maclaren.
.