sfm3166@ultb.isc.rit.edu (S.F. Modi) (12/27/89)
Hi everyone This is a trival question for this groop but I do need an answer quickly please !!!!. I am using lightspeed C (3.02) for a program. The calls DrawString("xxxx") will print xxxx in your window ( I have done the screen bounds etc). I cannot say printf("xxx") as it defaults to the compiler window. So how do you print a variable ? for example I want to print int money = 100. printf(" I have dollers %d",money). I could say :- DrawString(" I have dollers") BUT How do I print out the value held in the variable money Can I use DrawText ?? and if so how do I call it. If some one out there has any code I could look at I would be very gratefull. I would also ( if I am not imposing too much ) like to see some code for using Text Edit; though for the above case I would like to use something simple like DrawText. I thank you all very much and look forward to hearing from someone soon. Thank You. Sohrab Modi cornell!rochester!rit!ultb!sfm3166
oster@dewey.soe.berkeley.edu (David Phillip Oster) (12/27/89)
Str255 s; sprintf((char *) s, "money %d", moneyvar); CtoPstr((char *) s); MoveTo(12, 20); DrawString(s); will work. As for examples of TextEdit, see the MiniEdit example that came with your THINK C 3.02 compiler.
dowdy@apple.com (Tom Dowdy) (01/03/90)
In article <1837@ultb.isc.rit.edu> sfm3166@ultb.isc.rit.edu (S.F. Modi) writes: > say printf("xxx") as it defaults to the compiler window. So how do you print a variable ? for > example I want to print Well, this example might be a bit off base from what you want, but it certainly can be changed into what you want. I've seen versions of this called wprintf() that output into a scrolling window. I personally usually prefer to see things in Macsbug, because usually this code is only in for debugging. Follows is code to output printf() style into Macsbug. I use this with MPW and <stdarg.h>. Requires linking with C libraries. The runtime routines require A5, thus not too useful in VBL tasks and so forth (sorry, Tim). Uses 256 bytes of stack space for the temp string. Haven't tried this sort of thing with Lightspeed, maybe someone can convert it and let the world know. Hope this is useful to some folks out there... /* ---------------------------------------------------------- */ void debugprintf(char *sFormat, ...) /* Stolen from Geoff Coco. Take a printf style list of args, pass them on and debugstr them. Call as you would printf. */ { Str255 sOut; va_list pArgs; va_start(pArgs, sFormat); vsprintf(sOut, sFormat, pArgs); c2pstr(sOut); DebugStr(sOut); } // debugprintf Tom Dowdy Internet: dowdy@apple.COM Apple Computer MS:81EQ UUCP: {sun,voder,amdahl,decwrl}!apple!dowdy 20525 Mariani Ave AppleLink: DOWDY1 Cupertino, CA 95014 "The 'Ooh-Ah' Bird is so called because it lays square eggs."
oster@dewey.soe.berkeley.edu (David Phillip Oster) (01/05/90)
In article <5960@internal.Apple.COM> dowdy@apple.com (Tom Dowdy) writes: >I personally >usually prefer to see things in Macsbug, because usually this code is only >in for debugging. Tom is right, Here is dprintf() for THINK C.: dprintf(pat, arg)char *pat;int arg;{ char s[256]; s[0] = vsprintf(&s[1], pat, &arg) - 1; DebugStr((StringPtr) s); } Note, you'll need to have the sprintf library in your project. Also, I last ran this under THINK C v. 3. I'd check and see if V4 returns the count of characters generated from vsprintf(), in the manual, before trying to run this. > The mac is a detour in the inevitable march of mediocre computers. > drs@bnlux0.bnl.gov (David R. Stampf) --- David Phillip Oster -master of the ad hoc odd hack. Arpa: oster@dewey.soe.berkeley.edu Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu
beard@ux1.lbl.gov (Patrick C Beard) (01/05/90)
In article <33467@ucbvax.BERKELEY.EDU> oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) writes: >In article <5960@internal.Apple.COM> dowdy@apple.com (Tom Dowdy) writes: >>I personally >>usually prefer to see things in Macsbug, because usually this code is only >>in for debugging. > >Tom is right, Here is dprintf() for THINK C.: David's version assumed some things about vsprintf. Here is the more conventional way, and this does work under THINK C V4.0: #include <stdarg.h> void dprintf(char *sFormat, ...) { char sOut[256]; va_list pArgs; va_start(pArgs, sFormat); vsprintf(sOut, sFormat, pArgs); CtoPstr(sOut); DebugStr(sOut); } ------------------------------------------------------------------------------- - Patrick Beard, Macintosh Programmer (beard@lbl.gov) - - Berkeley Systems, Inc. ".......<dead air>.......Good day!" - Paul Harvey - -------------------------------------------------------------------------------