How to FSEEK previous line of text?

Martin Weitzel martin at mwtech.UUCP
Thu May 9 19:49:17 AEST 1991


In article <1991May8.154638.21318 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
>In article <4508.28269613 at iccgcc.decnet.ab.com> maslar at iccgcc.decnet.ab.com writes:
>>Does anyone know of a function or technique that is similar to FSEEK
>>that will allow me to go back to the previous line? ...
>
>There is no provision for this in the standard libraries, because it can
>be arbitrarily hard to implement on systems that store text files in odd
>ways.  You can build it yourself, however, by simply using ftell() to keep
>track of the location of the previous line, and fseek()ing there on demand.

Which brings us to the Question:

What is more portable in ANSI-C - ftell()/fseek() or fgetpos()/fsetpos().

As I understand, the former has some limitations if "really large" files
must be processed. On the other hand it has the advantage that at least on
binary streams you can calculate the number of bytes to skip forward or
backward from a known place. Since this ability is not needed here (nor
is it guaranteed for text files), I think fgetpos()/fsetpos() is the way
to go (provided the compiler of the person who posted the original
question is ANSI-ish enough to have these functions).
-- 
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.lang.c mailing list