Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cmcl2!yale!mintaka!spdcc!ima!dirtydog!karl From: karl@ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: sprintf badness Keywords: sprintf, sscanf Message-ID: <1991Jan21.212216.27724@dirtydog.ima.isc.com> Date: 21 Jan 91 21:22:16 GMT References: <473@bally.Bally.COM> <1991Jan21.004401.15257@nntp-server.caltech.edu> Sender: news@dirtydog.ima.isc.com (NEWS ADMIN) Distribution: usa Organization: Interactive Systems Lines: 19 In article <1991Jan21.004401.15257@nntp-server.caltech.edu> gceych@iago.caltech.edu writes: >> double k; >> sscanf(buf,"%4d%7f%4d",&i,&k,&j); > ^^^ >I believe this should be "%7lf", for a DOUBLE number. Right. This should fix the problem. >Same mistake is made in the next line of the program. >> printf("i = %d j = %d k= %7.2f",i,j,k); Wrong. For printf(), "%f" is correct and "%lf" is illegal. This unfortunate asymmetry is a result of history and the default widening rules. (You'll probably find that "%lf" works on your local implementation of printf(). But since "%f" also works and is Standard, that's the one to use. Fix it now, before you port to an implementation that works differently.) Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint