DAVE%UWF.BITNET@wiscvm.wisc.EDU (05/25/87)
All, I've got a (hopefully) simple problem with the printf statement, using Lattice C V3. My code looks something like this: while (i <= N0) { p = (a + b) / b; printf("\ni = %5d, ",i); printf("p = %lf, so there", p); if (abs(p - pl) / abs(p) < tol) { printf("\n\nMethod Returns %lf after %d iterations.\n", p, i); return (0); } i++; pl = p; (f(a) * f(p) > 0) ? (a = p) : (b = p); } The problem is that both of the two printf's that try to output the variable 'P' meet with disaster, in that both output the format spec, in this case, the %lf, but I also tried %f, %g, and %G, mostly in desperation. How does one output a (double) variable? Lost & 1/2, Dave Jaquay (DAVE@UWF.BITNET)
ark@alice.UUCP (05/26/87)
In article <7527@brl-adm.ARPA>, DAVE%UWF.BITNET@wiscvm.wisc.EDU writes: > The problem is that both of the two printf's that try to output the variable > 'P' meet with disaster, in that both output the format spec, in this case, > the %lf, but I also tried %f, %g, and %G, mostly in desperation. How does > one output a (double) variable? There are two versions of printf distributed with Lattice C. One has floating-point formats build in and the other doesn't. If you intend to print floating-point values, you must ask for the right ones. Look, for instance at the LINKMS batch file. If I remember right you must include LCM.LIB and LC.LIB in that order when you link.
gwyn@brl-smoke.UUCP (05/27/87)
In article <7527@brl-adm.ARPA> DAVE%UWF.BITNET@wiscvm.wisc.EDU writes: >the %lf, but I also tried %f, %g, and %G, mostly in desperation. %f and %g are the right things to try; since they didn't work, one concludes that your Lattice C implementation either doesn't support them at all or supports them in some funny way. You might check whether there's a separate floating-point support library you need to use that includes a more capable printf(). Note that %lf is not necessary, since it is not possible for printf() to receive a (float) (it would be coerced to a (double) when printf() is called).