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