f



scanf("%d. %d. %d",&d,&m,&y);

why scanf("%d. %d. %d",&d,&m,&y);

 is NOT reading the i/p 22 4 1972  correctly,
 whereas it is reading the i/p 22. 4. 1972 correctly ?.

Is it because of the dot in the format string of scanf ?
0
4/25/2008 8:09:54 AM
comp.lang.c 30657 articles. 5 followers. spinoza1111 (3246) is leader. Post Follow

2 Replies
906 Views

Similar Articles

[PageSpeed] 31

sophia wrote:
> why scanf("%d. %d. %d",&d,&m,&y);
> 
>  is NOT reading the i/p 22 4 1972  correctly,
>  whereas it is reading the i/p 22. 4. 1972 correctly ?.
> 
> Is it because of the dot in the format string of scanf ?

Yes, why did you put them there if you didn't expect them in the input?

-- 
Ian Collins.
0
ian-news (10155)
4/25/2008 8:16:01 AM
sophia wrote:

> 
> why scanf("%d. %d. %d",&d,&m,&y);
> 
>  is NOT reading the i/p 22 4 1972  correctly,
>  whereas it is reading the i/p 22. 4. 1972 correctly ?.
> 
> Is it because of the dot in the format string of scanf ?

Yes. If a character (or characters) in the format string do not have any
special meaning to scanf, then it'll look for a literal match of those
characters in the input.

Here is an extract from man(3) scanf:

The format string consists of a sequence of directives  which  describe
how  to  process  the sequence of input characters.  If processing of a
directive fails, no further input is  read,  and  scanf()  returns.   A
"failure"  can  be either of the following: input failure, meaning that
input characters were unavailable, or matching  failure,  meaning  that
the input was inappropriate (see below).

       A directive is one of the following:

       �      A  sequence of white-space characters (space, tab,
              newline, etc; see isspace(3)).  This directive matches 
              any  amount  of  white space, including none, in the
              input.

       �      An ordinary character (i.e., one other than white space
              or ?%?). This character must exactly match the next
              character of input.

       �      A conversion specification, which commences with a ?%?
              (percent) character.  A sequence of characters from the
              input is converted according to this specification, and
              the result is placed in the corresponding  pointer
              argument.  If the next item of input does not match the
              the conversion specification, the conversion fails ? this
              is a matching failure.

0
santosh.k83 (3969)
4/25/2008 8:18:42 AM
Reply: