Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: no error by fscanf on reading from output file |
| Date | 2011-10-31 08:50 +1300 |
| Message-ID | <9h5o4pFgakU3@mid.individual.net> (permalink) |
| References | (2 earlier) <slrn3vfsjaq22a.9k6.ike@iceland.freeshell.org> <9h4frvFgamU3@mid.individual.net> <j8jeto$sue$1@dont-email.me> <9h5jsbFgakU1@mid.individual.net> <0.b91d766b6392bf3ae1cf.20111030194003GMT.87hb2qfeuk.fsf@bsb.me.uk> |
On 10/31/11 08:40 AM, Ben Bacarisse wrote: > Ian Collins<ian-news@hotmail.com> writes: > >> On 10/31/11 01:11 AM, Eric Sosman wrote: >>> On 10/30/2011 4:23 AM, Ian Collins wrote: >>>> On 10/30/11 09:18 PM, Ike Naar wrote: >>>>> On 2011-10-30, Ian Collins<ian-news@hotmail.com> wrote: >>>>>> On 10/30/11 07:59 PM, V.Subramanian, India wrote: >>>>>>> if (fscanf(fp, "%d%d",&a,&b) == 2) >>>>>> >>>>>> You don't test the return of fscanf. Do so and see what happens. >>>>> >>>>> He does; he compares the return of fscanf with 2. >>>> >>>> Yes he does, but he does nothing if the test fails. >>> >>> Perhaps your newsreader has lopped off part of the O.P.'s code. >>> In the version I see, the "equals two" case goes down one path and >>> the "else" does something entirely different. Lightly edited: >> >> Entirely different in the sense that it doesn't check why fscanf >> failed. > > I think it does -- at least it tries to. The code fails because fp is > an output stream, and all tests to see why fscanf failed will be useless > on an output stream. The pattern used, though, is reasonable: test for > success (that fscanf reads the number of items required) and then test > for errors on the stream and for EOF. > > The only thing that could be added would be to save the return value and > report how many items matched or failed to match. I tend to do this > because it simplifies the EOF test, but that is a small matter of style. I guess I'm used to the POSIX behaviour where fscanf will set errno on failure. In this case, EOF will be returned and errno will be set to EBADF to indicate the file has not been opened for reading. -- Ian Collins
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
no error by fscanf on reading from output file "V.Subramanian, India" <subramanian100in@yahoo.com> - 2011-10-29 23:59 -0700
Re: no error by fscanf on reading from output file Ian Collins <ian-news@hotmail.com> - 2011-10-30 20:19 +1300
Re: no error by fscanf on reading from output file Ike Naar <ike@iceland.freeshell.org> - 2011-10-30 08:18 +0000
Re: no error by fscanf on reading from output file Ian Collins <ian-news@hotmail.com> - 2011-10-30 21:23 +1300
Re: no error by fscanf on reading from output file Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-10-30 08:11 -0400
Re: no error by fscanf on reading from output file Ian Collins <ian-news@hotmail.com> - 2011-10-31 07:38 +1300
Re: no error by fscanf on reading from output file Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-30 19:40 +0000
Re: no error by fscanf on reading from output file Ian Collins <ian-news@hotmail.com> - 2011-10-31 08:50 +1300
Re: no error by fscanf on reading from output file "V.Subramanian, India" <subramanian100in@yahoo.com> - 2011-10-30 00:01 -0700
Re: no error by fscanf on reading from output file Ike Naar <ike@iceland.freeshell.org> - 2011-10-30 08:39 +0000
Re: no error by fscanf on reading from output file Carlo Dapor <catull@gmail.com> - 2011-10-30 19:16 -0700
Re: no error by fscanf on reading from output file Ian Collins <ian-news@hotmail.com> - 2011-10-31 15:50 +1300
Re: no error by fscanf on reading from output file "V.Subramanian, India" <subramanian100in@yahoo.com> - 2011-10-30 22:55 -0700
Re: no error by fscanf on reading from output file pacman@kosh.dhis.org (Alan Curry) - 2011-10-31 07:14 +0000
Re: no error by fscanf on reading from output file Ian Collins <ian-news@hotmail.com> - 2011-10-31 20:56 +1300
Re: no error by fscanf on reading from output file Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-31 15:43 +0000
Re: no error by fscanf on reading from output file Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-10-31 01:35 -0700
Re: no error by fscanf on reading from output file Keith Thompson <kst-u@mib.org> - 2011-10-31 13:46 -0700
Re: no error by fscanf on reading from output file Ike Naar <ike@iceland.freeshell.org> - 2011-10-31 07:02 +0000
csiph-web