home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!sh.wide!wnoc-tyo-news!scslwide!wsgw!wsservra!sakamoto
- From: sakamoto@sm.sony.co.jp (Tomohiko Sakamoto)
- Newsgroups: comp.lang.c
- Subject: Where is an ANSI-C scanf funcion?
- Message-ID: <1992Sep3.071003.8218@sm.sony.co.jp>
- Date: 3 Sep 92 07:10:03 GMT
- Sender: news@sm.sony.co.jp (Usenet News System)
- Reply-To: sakamoto@sm.sony.co.jp
- Organization: Workstation Div., Supermicro Systems Group, Sony Corporation
- Lines: 26
- Nntp-Posting-Host: sak3
-
- main() {
- int n; float f; char s[20];
- f = 0.0; *s='\0';
- n = sscanf("2.7a-xyz", "%f %s", &f, s);
- printf("n=%d, f=%.1f, s='%s'\n", n, f, s);
- f = 0.0; *s='\0';
- n = sscanf("2.7e-xyz", "%f %s", &f, s);
- printf("n=%d, f=%.1f, s='%s'\n", n, f, s);
- }
- ----------------------------------------------------------
- Borland C++ Version 2.0, Microsoft C Version 5.10, and cc on 4.3BSD:
- n=2, f=2.7, s='a-xyz'
- n=2, f=2.7, s='xyz'
-
- cc on SunOS 4.1.2 and cc on SVR4:
- n=2, f=2.7, s='a-xyz'
- n=2, f=2.7, s='e-xyz'
-
- But ANSI C (ANSI X3.159-1989) p.139 says:
- n=2, f=2.7, s='a-xyz'
- n=0, f=0.0, s='' /* "2.7e-" fails to match "%f" */
-
- Can anybody explain this?
-
- --
- sakamoto@sm.sony.co.jp
-