Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #12321

Re: no error by fscanf on reading from output file

From pacman@kosh.dhis.org (Alan Curry)
Newsgroups comp.lang.c
Subject Re: no error by fscanf on reading from output file
Date 2011-10-31 07:14 +0000
Organization Aioe.org NNTP Server
Message-ID <j8lhsg$uis$1@speranza.aioe.org> (permalink)
References <9b198cc9-d374-4a14-a100-91b74eb12d9e@a12g2000prb.googlegroups.com> <88a48804-4b47-41f8-bd12-e5b8b4c7df85@m19g2000vbm.googlegroups.com> <9h6go1FcetU1@mid.individual.net> <721e72aa-54ae-4a90-997f-960266c961ff@u37g2000prh.googlegroups.com>

Show all headers | View raw


In article <721e72aa-54ae-4a90-997f-960266c961ff@u37g2000prh.googlegroups.com>,
V.Subramanian, India <subramanian100in@yahoo.com> wrote:
>
>Does 'fscanf' set the error indicator of a stream on error while
>reading the stream ? If so, ferror(fp) should succeed and the contents
>inside 'if (ferror(fp)) {...}' should be executed. Kindly provide a
>code for the above scenario. I am unable to come up with this code. I
>tried the following:

It's nice that you want to test your error handling code path, but injecting
an error that will be reported by ferror() is not easy. ferror() is the
indicator of I/O errors, which usually have a cause that exists outside your
program, like a hard disk with bad sectors.

Check the return value of fscanf first. If it returned EOF, then you can call
ferror() to distinguish between a normal end-of-file condition and an I/O
error. In all other cases, ferror() won't be useful.

-- 
Alan Curry

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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