Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!mcsun!unido!mikros!mwtech!martin From: martin@mwtech.UUCP (Martin Weitzel) Newsgroups: comp.lang.c Subject: Re: How to FSEEK previous line of text? Message-ID: <1132@mwtech.UUCP> Date: 9 May 91 09:49:17 GMT References: <4508.28269613@iccgcc.decnet.ab.com> <1991May8.154638.21318@zoo.toronto.edu> Reply-To: martin@mwtech.UUCP (Martin Weitzel) Organization: MIKROS Systemware, Darmstadt/W-Germany Lines: 23 In article <1991May8.154638.21318@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >In article <4508.28269613@iccgcc.decnet.ab.com> maslar@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@mwtech.UUCP, voice: 49-(0)6151-6 56 83