473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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 ?
Jun 27 '08 #1
2 11247
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.
Jun 27 '08 #2
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.

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Przemo Drochomirecki | last post by:
hi, SCANF is not well described in my books, i'd like to do this stuff: 1) read all numbers from a line, separated by #32 2) read all numbers from a line, separaed by ',' 3) read whole line ...
14
by: Peter Mount | last post by:
Hello I'm having trouble with " scanf("%c", &answer);" on line 20 below. When I run the program in cygwin on Windows 98SE it skips that line completely and ends the program. Does scanf have...
18
by: Martin Jørgensen | last post by:
Hi, Today I got a really strange problem... I've made myself a data-file and I read in data from that file.... When I read something like this line: 03 04 05, 00 04 01, 05 03 07, 08 03...
9
by: Cao Yi | last post by:
Hi, here's a fract of codes, and what's the line "scanf("%lf%*", &cvi)" doing? ============================= do { printf("\nCoefficient: "); scanf("%lf%*", &cvi); getchar(); } while (cvi <=...
1
by: lovecreatesbea... | last post by:
I've read some post on sent by pete and other experts, and have doubts on following lines of code. 1. I think the xstr macro isn't needed, is it safe to just use the str macro in the following...
3
by: cdarunkumar | last post by:
please i want what is conio.h and scanf("%5d",&a)
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.