Xref: utzoo comp.unix.wizards:11588 comp.lang.c:13144 Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uwmcsd1!marque!uunet!mcvax!hp4nl!nikhefk!tomp From: tomp@nikhefk.UUCP (Tom Ploegmakers) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Re: Problem with printf() Message-ID: <429@nikhefk.UUCP> Date: 6 Oct 88 12:30:13 GMT References: <504@imec.UUCP> Reply-To: tomp@nikhefk.UUCP (Tom Ploegmakers) Organization: Nikhef-K, Amsterdam (the Netherlands). Lines: 34 In article <504@imec.UUCP> croes@imec.UUCP (Kris Croes) writes: > main() > { > int i = 17; > float f = 17.0; > > printf("%d %f\n",i,i); /*1*/ > printf("%d %f\n",f,f); /*2*/ > } > >Its output is: >17 0.000000 >17032 0.000000 > ^^^^^^^^ Shouldn't this be 17.00000 ? > This one has bitten me once too. The problem is that floats are not passed to functions on the stack, but by passing a pointer. That is, sometimes, you should check your compiler. To make it work use: printf("%d %f\n",i,(float)i); /*1*/ printf("%d %f\n",(int)f,f); /*2*/ Suc6. tom ploegmakers NIKHEF/K-CSG (tomp@nikhefk.uucp) po.box 4395, 1009 AJ Amsterdam, the Netherlands. -- tom ploegmakers NIKHEF/K-CSG (tomp@nikhefk.uucp) po.box 4395, 1009 AJ Amsterdam, the Netherlands.