Xref: utzoo comp.unix.wizards:11633 comp.lang.c:13199 Path: utzoo!attcan!uunet!husc6!bloom-beacon!apple!rutgers!bellcore!faline!thumper!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Re: Problem with printf() Message-ID: <8277@alice.UUCP> Date: 8 Oct 88 14:31:27 GMT References: <504@imec.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 32 In article <504@imec.UUCP>, croes@imec.uucp (Kris Croes) writes: > Hello NetLand, > May I introduce to you... > A little program containing a big problem. > 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 ? A float is automatically cast to double when used as an argument. Thus f probably takes up two words on the stack and %d picks off only one. Why do you want to use %d to print a float anyway? Incidentally, the %g format is usually more useful than %f. -- --Andrew Koenig ark@europa.att.com