home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!agate!emarkp
- From: emarkp@ocf.berkeley.edu (E. Mark Ping)
- Newsgroups: comp.lang.c
- Subject: How to randomly access files in C?
- Date: 1 Sep 1992 00:18:50 GMT
- Organization: U.C. Berkeley Open Computing Facility
- Lines: 42
- Distribution: world
- Message-ID: <17uctaINNco3@agate.berkeley.edu>
- NNTP-Posting-Host: plague-ether.berkeley.edu
-
-
- The subject line pretty much says it all. Basically, I'm reading a file
- with fgets, and I want to be able to 'go back' a few lines if a certain
- condition is true.
-
- If I were going through a char array, I'd have two pointers, and would
- reset the second if the condition were true, i.e.:
-
- main()
- {
- char line[]="This is a test line."
- char *a, *b;
-
- a = line;
- b = a;
-
- while (*a != NULL)
- {
- if (foo(a))
- {
- a = b;
- }
- else bar();
- b = a;
- a++;
- }
- }
-
- Now how can I emulate that behavior with successive lines in a file?
- (Sorry if the above code is somewhat icky, it's just a random example to
- clarify the question.)
-
- Thanks for any help.
- --
- E. Mark Ping
- emarkp@ocf.Berkeley.EDU
-
- "Stand aside, I take large steps." --Michael Dorn
- "Say, that's a nice bike." --Cyberdyne Systems T-1000
- "Pituita es." --Unknown Latin Scholar
-
- And of course, this in no way reflects my views of UC Berkeley.
-