Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!caen!ox.com!tbomb.ice.com!time From: time@tbomb.ice.com (Tim Endres) Newsgroups: comp.sys.mac.programmer Subject: RE: Drawstring Question Message-ID: <1CE00001.ale2i0@tbomb.ice.com> Date: 3 Dec 90 19:29:57 GMT Reply-To: time@tbomb.ice.com Organization: ICE Engineering, Inc. Lines: 57 X-Mailer: uAccess - Mac Release: 1.0.3 In article <31268.275A511A@stjhmc.fidonet.org>, Chris.Gehlker@p12.f56.n114.z1.fidonet.org (Chris Gehlker) writes: > > Now there is a new problem: > > Since I am using a drawing Window as my output medium, I can not use > > the standard output functions (printf). I want to display the values of > > some variables though. Since I have to use DrawString, this seems to be > > a problem. For example, how do I draw a properly formatted floating > > point number?? Drawstring does not give you formatting options and > > seems to require a string. How do you get around this ?? Any ideas?? > > I guess num2str() is a well kept secret. Apple documents it in the SANE > Manual rather than in IM. Anyhoo, it's: > void num2str(decform *, extended, void *); in SANE.h. A decform is a > struct that set the style to normal or scientific and tells the function how > many decimal points to use for rounding. You pass it an Str255 in the final > argument and it fills it in for you. Then you pass it to DrawString(). > > See the following fragment: > ... > extended x = 1.2345; > Str255outString; > decformf; > ... > f.style = FIXEDDECIMAL; > f. digits = 8; > num2str(&f, x, outString); > DrawString(outString); > ... --- OR --- static char drawf_string[512]; /* ** NOTE: The limitation on the number of arguments. ** You may specify more if you need them. */ drawf(format_str, arg0, arg1, arg2, arg3, arg4, arg5) char *format_str; char *arg0, *arg1, *arg2, *arg3, *arg4, *arg5; { sprintf(drawf_string, format_str, arg0, arg1, arg2, arg3, arg4, arg5); c2pstr(drawf_string); DrawString(drawf_string); } main() { drawf("Print %s", "Hello World"); } ------------------------------------------------------------- Tim Endres | time@ice.com ICE Engineering | uunet!ice.com!time 8840 Main Street | Whitmore Lake MI. 48189 | (313) 449 8288