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


Groups > comp.lang.c > #12775

Re: newby question on C I/O

From Eric Sosman <esosman@ieee-dot-org.invalid>
Newsgroups comp.lang.c
Subject Re: newby question on C I/O
Date 2011-11-05 09:21 -0400
Organization A noiseless patient Spider
Message-ID <j93dan$ath$1@dont-email.me> (permalink)
References <0f0ee88e-09f4-43ca-8c95-84f9a4846455@c1g2000vbw.googlegroups.com> <j924gs$d7s$1@dont-email.me> <slrn3vfsjb9na4.b8e.ike@iceland.freeshell.org> <j939f2$l41$1@dont-email.me>

Show all headers | View raw


On 11/5/2011 8:16 AM, James Kuyper wrote:
> On 11/05/2011 02:52 AM, Ike Naar wrote:
>> On 2011-11-05, James Kuyper<jameskuyper@verizon.net>  wrote:
>>> 	while(fscanf(infile, "%f%f%3s\n",
>>> 	        values[j], costs[j], statuses[j]) == 3)
>>
>> The infamous scanf trap :-)
>>
>>    	&values[j],&costs[j], statuses[j]) == 3)
>
> Sorry for the mistake. I don't use fscanf() very often, and not just
> because of the problems I mentioned with out-of-range numeric values.
> For the last 15 years, most of the files my programs read are in HDF-EOS
> format, which they read using third-party library functions. Most of the
> rest are in  CCSDS Production Data Se format, which they read using fread().
>
>> Just curious: is the trailing "\n" in the fscanf format useful,
>> or would the behaviour be the same if it were omitted?
>
> I remember reaching the conclusion, a decade or two ago, that it did
> have some useful effect, but I can't find support for that concept by
> reading the standard's description of fscanf(). I believe I was assuming
> that a white-space directive requires the presence of at least one
> corresponding character of white-space, but I can't find explicit
> wording to that effect.

     A single white space character in the format string matches any
number of white space characters in the input, including zero.  All
that matters is the whiteness: '\n' will gobble '\n', but also '\t'
and '\r' and '\v' and '\f' and ' ', and perhaps other locale-specific
spaces, in solid runs or in combinations.

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

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


Thread

newby question on C I/O "analyst41@hotmail.com" <analyst41@hotmail.com> - 2011-11-04 15:07 -0700
  Re: newby question on C I/O Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-04 20:50 -0400
    Re: newby question on C I/O "analyst41@hotmail.com" <analyst41@hotmail.com> - 2011-11-04 18:57 -0700
    Re: newby question on C I/O "analyst41@hotmail.com" <analyst41@hotmail.com> - 2011-11-07 17:10 -0800
      Re: newby question on C I/O Ian Collins <ian-news@hotmail.com> - 2011-11-08 14:47 +1300
      Re: newby question on C I/O "BartC" <bc@freeuk.com> - 2011-11-08 01:52 +0000
      Re: newby question on C I/O Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-07 20:56 -0500
        Re: newby question on C I/O Edward Rutherford <edward.p.rutherford79@REMOVETHIS.gmail.com> - 2011-11-08 20:27 +0000
          Re: newby question on C I/O Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-08 20:48 -0500
          Re: newby question on C I/O "BartC" <bc@freeuk.com> - 2011-11-09 11:12 +0000
            Re: newby question on C I/O James Kuyper <jameskuyper@verizon.net> - 2011-11-09 07:02 -0500
              Re: newby question on C I/O Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-11-09 16:12 +0000
        Re: newby question on C I/O - SUCCESS "analyst41@hotmail.com" <analyst41@hotmail.com> - 2011-11-08 16:12 -0800
  Re: newby question on C I/O James Kuyper <jameskuyper@verizon.net> - 2011-11-04 21:46 -0400
    Re: newby question on C I/O Ike Naar <ike@iceland.freeshell.org> - 2011-11-05 06:52 +0000
      Re: newby question on C I/O Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-11-05 04:13 -0700
      Re: newby question on C I/O James Kuyper <jameskuyper@verizon.net> - 2011-11-05 08:16 -0400
        Re: newby question on C I/O Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-05 09:21 -0400
      Re: newby question on C I/O Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-11-05 09:13 -0400
    Re: newby question on C I/O David Thompson <dave.thompson2@verizon.net> - 2011-11-21 02:39 -0500
      Re: newby question on C I/O James Kuyper <jameskuyper@verizon.net> - 2011-11-21 10:05 -0500
        Re: newby question on C I/O David Thompson <dave.thompson2@verizon.net> - 2012-01-19 02:40 -0500
  Re: newby question on C I/O "BartC" <bc@freeuk.com> - 2011-11-06 21:23 +0000
  Re: newby question on C I/O "analyst41@hotmail.com" <analyst41@hotmail.com> - 2011-11-10 18:00 -0800
    Re: newby question on C I/O Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-11-11 01:35 -0800
      Re: newby question on C I/O gazelle@shell.xmission.com (Kenny McCormack) - 2011-11-11 11:26 +0000
        Re: newby question on C I/O Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-11-11 04:41 -0800
          Re: newby question on C I/O gazelle@shell.xmission.com (Kenny McCormack) - 2011-11-11 14:14 +0000
            Re: newby question on C I/O Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-11-11 07:02 -0800
              Re: newby question on C I/O gazelle@shell.xmission.com (Kenny McCormack) - 2011-11-11 15:44 +0000

csiph-web