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.