home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18697 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.3 KB

  1. Path: sparky!uunet!spool.mu.edu!sdd.hp.com!elroy.jpl.nasa.gov!nntp-server.caltech.edu!eql.caltech.edu!rankin
  2. From: rankin@eql.caltech.edu (Pat Rankin)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: More File read problems. Help I'm new and confused...
  5. Date: 19 Dec 1992 19:15 PST
  6. Organization: California Institute of Technology
  7. Lines: 17
  8. Distribution: world
  9. Message-ID: <19DEC199219154929@eql.caltech.edu>
  10. References: <1gl9bhINN3f7@mirror.digex.com> <1992Dec19.181840.19871@eagercon.com>
  11. NNTP-Posting-Host: eql10.caltech.edu
  12. News-Software: VAX/VMS VNEWS 1.41    
  13.  
  14. >>       case '\'': while(j==0)
  15. >>                { (ch=getc(fptr)); if (ch='\'') j=1; }
  16. > Better coding style (at least more ideomatic) is
  17. >            while (getc(fptr) != '\'') ;
  18. > No unneeded variables used.
  19.  
  20.      This may appear to be better style than the original, but they both
  21. have the same serious bug.  What happens if/when no matching single quote
  22. is encountered before end-of-file?  Such code must always have [at least]
  23. two checks, so the variable is not unneeded unless you want to replace
  24. the empty statement with ``if (feof(fptr)) break;'' (adding ``&& !feof(...''
  25. to the condition instead of `if' will work too).  A local variable is
  26. bound to be more efficient (as long as it's `int' rather than `char' that
  27. is ;-), and may or may not make the code clearer,
  28.  
  29.         Pat Rankin, rankin@eql.caltech.edu
  30.