Velocity Reviews > Scanf Problem

Scanf Problem

LJ
Guest
Posts: n/a

 07-07-2011
K&R says that the scanf format string may contain ordinary characters,
which are expected to match the next non-white space character of the
input stream.

However when I am reading the date given as 25 /
12 / 1988 using scanf( "%d/%d/%d", &day, &month,
&year ); it is only reading the day. Why is it not reading the month
and year??

John Gordon
Guest
Posts: n/a

 07-07-2011
In <(E-Mail Removed)> LJ <(E-Mail Removed)> writes:

> K&R says that the scanf format string may contain ordinary characters,
> which are expected to match the next non-white space character of the
> input stream.

> However when I am reading the date given as 25 /
> 12 / 1988 using scanf( "%d/%d/%d", &day, &month,
> &year ); it is only reading the day. Why is it not reading the month
> and year??

Probably because your input contains spaces which the format string wasn't
told to look for.

--
John Gordon A is for Amy, who fell down the stairs
http://www.velocityreviews.com/forums/(E-Mail Removed) B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

LJ
Guest
Posts: n/a

 07-07-2011
On Jul 7, 9:29*am, John Gordon <(E-Mail Removed)> wrote:
> In <(E-Mail Removed)> LJ<(E-Mail Removed)> writes:
>
> > K&R says that the scanf format string may contain ordinary characters,
> > which are expected to match the next non-white space character of the
> > input stream.
> > However when I am reading the date given as 25 * * * * * /
> > 12 * * */ * * * * 1988 *using scanf( "%d/%d/%d", &day, &month,
> > &year ); it is only reading the day. Why is it not reading the month
> > and year??

>
> Probably because your input contains spaces which the format string wasn't
> told to look for.
>
> --
> John Gordon * * * * * * * * * A is for Amy, who fell down the stairs
> (E-Mail Removed) * * * * * * *B is for Basil, assaulted by bears
> * * * * * * * * * * * * * * * * -- EdwardGorey, "The Gashlycrumb Tinies"

That doesn't answer my question, '/' should match the next non-
whitespace character and in input that character is '/' only, so scanf
shud read all the three dates

Ike Naar
Guest
Posts: n/a

 07-07-2011
On 2011-07-07, LJ <(E-Mail Removed)> wrote:
> On Jul 7, 9:29?am, John Gordon <(E-Mail Removed)> wrote:
>> In <(E-Mail Removed)> LJ <(E-Mail Removed)> writes:
>>
>> > K&R says that the scanf format string may contain ordinary characters,
>> > which are expected to match the next non-white space character of the
>> > input stream.
>> > However when I am reading the date given as 25 ? ? ? ? ? /
>> > 12 ? ? ?/ ? ? ? ? 1988 ?using scanf( "%d/%d/%d", &day, &month,
>> > &year ); it is only reading the day. Why is it not reading the month
>> > and year??

>>
>> Probably because your input contains spaces which the format string wasn't
>> told to look for.

>
> That doesn't answer my question, '/' should match the next non-
> whitespace character and in input that character is '/' only, so scanf
> shud read all the three dates

the whitespace.

Malcolm McLean
Guest
Posts: n/a

 07-07-2011
On Jul 7, 9:40*am, LJ <(E-Mail Removed)> wrote:
>
> That doesn't answer my question, '/' should match the next non-
> whitespace character and in input that character is '/' only, so scanf
> shud read all the three dates
>

The documentation you read is a bit confusing.

Whitespace matches whitespace, all other characters match themselves,
except for format fields introduced by %, and the % character itself.
--
Lots of programming goodies on my website
http://www.malcolmmclean.site11.com/www

lawrence.jones@siemens.com
Guest
Posts: n/a

 07-10-2011
LJ <(E-Mail Removed)> wrote:
> K&R says that the scanf format string may contain ordinary characters,
> which are expected to match the next non-white space character of the
> input stream.
>
> However when I am reading the date given as 25 /
> 12 / 1988 using scanf( "%d/%d/%d", &day, &month,
> &year ); it is only reading the day. Why is it not reading the month
> and year??

Because the paraphrase above is not correct: ordinary characters are
expected to match the next characters from the stream, they do not skip
--
Larry Jones

It COULD'VE happened by accident! -- Calvin