home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!know!cass.ma02.bull.com!think.com!rpi!batcomputer!cornell!uw-beaver!uw-coco!nwnexus!seanews!eskimo!maven
- From: maven@eskimo.celestial.com (Norman Hamer)
- Newsgroups: comp.lang.c
- Subject: Novice Questions
- Message-ID: <1992Aug30.004740.8973@eskimo.celestial.com>
- Date: 30 Aug 92 00:47:40 GMT
- Organization: <<< ESKIMO NORTH (206)-FOR-EVER >>>
- Lines: 49
-
- I have a couple questions which have been bugging the living <expletive
- deleted> out of me.
-
- Yes, I've read the FAQ...
-
- 1. Given a char array, say char foo[256];, is *foo the same as foo[0]
- and is foo+x the same as foo[x] in all implementations?
-
- 2. What's the best way to read in a text configuration file? I've seen
- code like this:
-
- /* Assume open file */
-
- fgets(line, 80, fd);
- while(!feof(fd))
- {
- /* Muck with the data */
- fgets(line, 80, fd);
- }
-
- and like this:
-
- while(fgets(line, 80, fd) != NULL)
- {
- /*Muck with the data */
- }
-
- and like this:
-
- while(!feof(fd))
- {
- fgets(line, 80, fd);
- if(feof(fd))
- break;
- /* Muck with the data */
- }
-
- Which one is best and why? Which is the least likely to provide
- erroneous results (the last one if you forget the second feof() will
- sometimes leave you with a portion of the last line... not all of it and
- not a null string)
-
- Thanks. Please reply by mail, as I can't read the newsgroup as often as
- I wish.
- --
- /* ------------------------------------------------------------ */
- /* Norman C. Hamer */
- /* maven@eskimo.celestial.com (USENet) */
- /* The Maven@The Mavenry (CitNet) */
-