home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!uunet.ca!canrem!telly!druid!darcy
- From: darcy@druid.uucp (D'Arcy J.M. Cain)
- Subject: Re: ....question abt scanf....acts funny....!!!
- Message-ID: <1992Aug13.051302.19661@druid.uucp>
- Date: Thu, 13 Aug 1992 05:13:02 GMT
- References: <1992Aug11.183513.6874@baarsa.bell-atl.com>
- Organization: D'Arcy Cain Consulting
- Lines: 31
-
- [ quoted message reformatted with, I'm sure, no change in text. ]
-
- ddlz0hv@baarsa.bell-atl.com (Ravi Shankar) writes:
- >and had a problem that we cannot quite figure. The program works
- >correctly as long as the anticipated input values are used. However,
- >when you enter a character value at the temperature prompt, the scanf
-
- Hmmm. Scanf does strange things when other than anticipated text is
- entered? Stop the presses. :-)
-
- >All suggestions are welcome.........
-
- From the FAQ (Not exactly applicable but close enough):
-
- 13.3: When I read from the keyboard with scanf(), it seems to hang
- until I type one extra line of input.
-
- A: scanf() was designed for free-format input, which is seldom what
- you want when reading from the keyboard. In particular, "\n" in
- a format string means, not to expect a newline, but to read and
- discard characters as long as each is a whitespace character.
-
- It is usually better to use fgets() to read a whole line, and
- then use sscanf() or other string functions to parse the line
- buffer.
-
- --
- D'Arcy J.M. Cain (darcy@druid.com) |
- D'Arcy Cain Consulting | There's no government
- Toronto, Ontario, Canada | like no government!
- +1 416 424 2871 DoD#0082 |
-