home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 13145 < prev    next >
Encoding:
Text File  |  1992-09-02  |  1.1 KB  |  39 lines

  1. Path: sparky!uunet!sun-barr!sh.wide!wnoc-tyo-news!scslwide!wsgw!wsservra!sakamoto
  2. From: sakamoto@sm.sony.co.jp (Tomohiko Sakamoto)
  3. Newsgroups: comp.lang.c
  4. Subject: Where is an ANSI-C scanf funcion?
  5. Message-ID: <1992Sep3.071003.8218@sm.sony.co.jp>
  6. Date: 3 Sep 92 07:10:03 GMT
  7. Sender: news@sm.sony.co.jp (Usenet News System)
  8. Reply-To: sakamoto@sm.sony.co.jp
  9. Organization: Workstation Div., Supermicro Systems Group, Sony Corporation
  10. Lines: 26
  11. Nntp-Posting-Host: sak3
  12.  
  13. main() {
  14.     int n; float f; char s[20];
  15.     f = 0.0; *s='\0';
  16.     n = sscanf("2.7a-xyz", "%f %s", &f, s);
  17.     printf("n=%d, f=%.1f, s='%s'\n", n, f, s);
  18.     f = 0.0; *s='\0';
  19.     n = sscanf("2.7e-xyz", "%f %s", &f, s);
  20.     printf("n=%d, f=%.1f, s='%s'\n", n, f, s);
  21. }
  22. ----------------------------------------------------------
  23. Borland C++ Version 2.0, Microsoft C Version 5.10, and cc on 4.3BSD:
  24.     n=2, f=2.7, s='a-xyz'
  25.     n=2, f=2.7, s='xyz'
  26.  
  27. cc on SunOS 4.1.2 and cc on SVR4:
  28.     n=2, f=2.7, s='a-xyz'
  29.     n=2, f=2.7, s='e-xyz'
  30.  
  31. But ANSI C (ANSI X3.159-1989) p.139 says:
  32.     n=2, f=2.7, s='a-xyz'
  33.     n=0, f=0.0, s=''    /* "2.7e-" fails to match "%f" */
  34.  
  35. Can anybody explain this?
  36.  
  37. --
  38. sakamoto@sm.sony.co.jp
  39.