fgets reading a configuration file: 
Author Message
 fgets reading a configuration file:

compiles OK but output wrong


>int main (int argc, char **argv)

>    }
>}/*end main */

>what i want the program to do is read 2 configuration files and print
>their contents without the comments

>pointed to by the index [j] which is incremented in the for loop until
>it reaches i (formerly the number of newlines plus 1)

>i must have become tired and missed something because the logic must
>be wrong, since it compiles without warnings.

Now there's a first!  Imagine that!  It compiles OK, but it
doesn't work!

I am going to confess that I did not read your code closely.
The reason I didn't is that it has all the classic symptoms of
getting things wrong by being too clever, under the mistaken notion
that there is some value in making "tight code."  Also, unlike good
code, it was not immediately obvious what the program was supposed
to do.

If you want to write a program to, say,

Do A
Do B

Then code that.  Don't worry about making it compact, and don't try
to squish A and B into the same piece of code with some clever dance
using pointers and whatnot.  

First get it right.  On that road, just code what you want.  If you
are going to read lines from argv[1], then argv[2], just do that.
Don't put them in a loop, with some special cases depending upon
whether i is 1 or 2.  If you want to ignore lines that begin with
#, then just read the lines in, test the first character for #, and
then . . .
(Left as an exercise for the poster)

Don't waste your time trying to squeeze milliseconds (maybe even
microseconds) out of run time of some program unless that is REALLY
NECESSARY.  (It almost never is.)

See Kernighan's book "The Practice of Programming."

Good luck.

Fri, 18 Feb 2005 11:42:39 GMT  
 [ 1 post ] 

 Relevant Pages 

1. fgets reading a configuration file: compiles OK but output wrong

2. reading a configuration file

3. reading in configuration files

4. Reading a configuration file

5. reading a configuration file

6. how to: XML file as application configuration file

7. Length of string read by fgets

8. Problems with fgets and reading in a number

9. fgets() read int?

10. fgets(): Reading Line without max arg

11. read and fgets

12. How to read only a specified # of chars with fgets()


Powered by phpBB® Forum Software