home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 12974 < prev    next >
Encoding:
Internet Message Format  |  1992-08-30  |  1.6 KB

  1. Path: sparky!uunet!know!cass.ma02.bull.com!think.com!rpi!batcomputer!cornell!uw-beaver!uw-coco!nwnexus!seanews!eskimo!maven
  2. From: maven@eskimo.celestial.com (Norman Hamer)
  3. Newsgroups: comp.lang.c
  4. Subject: Novice Questions
  5. Message-ID: <1992Aug30.004740.8973@eskimo.celestial.com>
  6. Date: 30 Aug 92 00:47:40 GMT
  7. Organization: <<< ESKIMO NORTH (206)-FOR-EVER >>>
  8. Lines: 49
  9.  
  10. I have a couple questions which have been bugging the living <expletive
  11. deleted> out of me.
  12.  
  13.  Yes, I've read the FAQ...
  14.  
  15.  1. Given a char array, say char foo[256];, is *foo the same as foo[0]
  16. and is foo+x the same as foo[x] in all implementations?
  17.  
  18.  2. What's the best way to read in a text configuration file? I've seen
  19. code like this:
  20.  
  21.  /* Assume open file */
  22.  
  23.  fgets(line, 80, fd);
  24.  while(!feof(fd))
  25.  {
  26.    /* Muck with the data */
  27.    fgets(line, 80, fd);
  28.  }
  29.  
  30.  and like this:
  31.  
  32.  while(fgets(line, 80, fd) != NULL)
  33.  {
  34.    /*Muck with the data */
  35.  }
  36.  
  37.  and like this:
  38.  
  39.  while(!feof(fd))
  40.  {
  41.     fgets(line, 80, fd);
  42.     if(feof(fd))
  43.         break;
  44.     /* Muck with the data */
  45.  }
  46.  
  47.  Which one is best and why? Which is the least likely to provide
  48. erroneous results (the last one if you forget the second feof() will
  49. sometimes leave you with a portion of the last line... not all of it and
  50. not a null string)
  51.  
  52.  Thanks. Please reply by mail, as I can't read the newsgroup as often as
  53. I wish.
  54. -- 
  55. /* ------------------------------------------------------------ */
  56. /* Norman C. Hamer                                              */
  57. /* maven@eskimo.celestial.com (USENet)                          */
  58. /* The Maven@The Mavenry      (CitNet)                          */
  59.