home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 13045 < prev    next >
Encoding:
Text File  |  1992-08-31  |  1.3 KB  |  54 lines

  1. Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!agate!emarkp
  2. From: emarkp@ocf.berkeley.edu (E. Mark Ping)
  3. Newsgroups: comp.lang.c
  4. Subject: How to randomly access files in C?
  5. Date: 1 Sep 1992 00:18:50 GMT
  6. Organization: U.C. Berkeley Open Computing Facility
  7. Lines: 42
  8. Distribution: world
  9. Message-ID: <17uctaINNco3@agate.berkeley.edu>
  10. NNTP-Posting-Host: plague-ether.berkeley.edu
  11.  
  12.  
  13.   The subject line pretty much says it all.  Basically, I'm reading a file
  14. with fgets, and I want to be able to 'go back' a few lines if a certain
  15. condition is true.
  16.  
  17.   If I were going through a char array, I'd have two pointers, and would
  18. reset the second if the condition were true, i.e.:
  19.  
  20. main()
  21. {
  22.     char line[]="This is a test line."
  23.     char *a, *b;
  24.  
  25.     a = line;
  26.     b = a;
  27.  
  28.     while (*a != NULL)
  29.     {
  30.         if (foo(a))
  31.         {
  32.             a = b;
  33.         }
  34.         else bar();
  35.         b = a;
  36.         a++;
  37.     }
  38. }
  39.  
  40.   Now how can I emulate that behavior with successive lines in a file?
  41. (Sorry if the above code is somewhat icky, it's just a random example to
  42. clarify the question.)
  43.  
  44.   Thanks for any help.
  45. -- 
  46. E. Mark Ping
  47. emarkp@ocf.Berkeley.EDU
  48.  
  49.   "Stand aside, I take large steps."    --Michael Dorn
  50.   "Say, that's a nice bike."            --Cyberdyne Systems T-1000
  51.   "Pituita es."                         --Unknown Latin Scholar
  52.  
  53. And of course, this in no way reflects my views of UC Berkeley.
  54.