Re: backspace error (reading file from the end)



Richard Maine wrote:

On Sun, 6 Aug 2006 23:03:51 -0700, leaf wrote
(in article <1154930631.268787.138040@xxxxxxxxxxxxxxxxxxxxxxxxxxx>):
(snip)

Backspacing from the current record n is performed by rewinding to the
start of the file and then performing n-1 successive READs to reach the
previous record.

The standard says nothing like this. I didn't even think it was a particularly common implementation choice. Why would it be for formatted files in most current systems? I'd expect the system to be able to search backwards for the previous record terminator pretty easily. Since I tend to avoid BACKSPACE, I guess I'm not sure on this - I probably wouldn't have noticed. But still, such an implementation would moderately surprise me.

Many Fortran I/O systems use the C library for doing I/O.

The C library routines ftell() and fseek() are used to find a position
in a file, and seek to a specific position. One can, for example,
use fseek() to seek to a specific (negative) offset from the end of
a file. For text files, with the t modifier on the fopen() call, the
C standard puts many restriction on the use of fseek(). For many systems, the value returned by ftell() is the byte offset into the file.
For systems like DOS and Windows, where the line terminator is more than
one character, it is converted to '\n' on input, and back again on
output. A relative call to fseek(), or doing arithmetic on the value
returned by ftell() is not guaranteed to give the right position: the
system doesn't know how many line terminators will be in a give block
of file data.

For the file systems used by IBM for MVS and CMS, the C problem is different. The system does have the ability to do backspace, but
not to find the byte offset of a given position in a file. In some
cases the C library must read the file up to the current position
to compute the byte offset or to position to a specific offset.
For those systems, the Fortran I/O system is not usually based on the C library. In some cases, the value returned by ftell() is a combination of the block number and offset into the current block, as allowed by C for text files.

-- glen

.



Relevant Pages

  • Re: textvsbinary
    ... Furthermore, for analogous reasons, the fseek and ftell functions do ... Does it mean that offset values are those which can be represented by ... Unix-like systems use a single ASCII LF character to indicate the end ...
    (comp.lang.c)
  • Re: Text mode fseek/ftell
    ... The platform is Windows, where text files use CF+LF to ... Will be able to do more things with fseek if you ... While you are now at offset 12 within the file, ftell() will return 14, ...
    (comp.lang.c)
  • Re: Text mode fseek/ftell
    ... Will be able to do more things with fseek if you ... While you are now at offset 12 within the file, ftell() will return 14, ... If the file is in Unix format (with ...
    (comp.lang.c)
  • Re: fseek
    ... >>open the same file as binary, then use the results of fseek and ftell ... "For a text stream, either offset shall be zero, or offset shall be a ... a stream associated with the same file_ and whence shall be SEEK_SET." ...
    (comp.lang.c)
  • Re: feof(), fseek(), fread()
    ... offset of a file and still be able to detect EOF?i.e. ... this without fseek(), that's why I posted this question. ... EOF is a macro defined in stdio.h probably as.. ... eoff = ftell; ...
    (comp.lang.c)