home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12262 < prev    next >
Encoding:
Text File  |  1992-08-12  |  1.6 KB  |  42 lines

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