Path: utzoo!utgpu!water!watmath!clyde!rutgers!ucla-cs!cit-vax!tybalt.caltech.edu!palmer From: palmer@tybalt.caltech.edu (David Palmer) Newsgroups: comp.sys.mac Subject: Re: sprintf() bug? Message-ID: <5349@cit-vax.Caltech.Edu> Date: 28 Jan 88 00:51:00 GMT References: <4VzXREy00WABE7k0FU@andrew.cmu.edu> Sender: news@cit-vax.Caltech.Edu Reply-To: palmer@tybalt.caltech.edu.UUCP (David Palmer) Organization: California Institute of Technology Lines: 26 In article <4VzXREy00WABE7k0FU@andrew.cmu.edu> rs4u+@andrew.cmu.edu (Richard Siegel) writes: >Additional recommendation: to avoid having to use CtoPstr, just use the "\p" >at the beginning of the string: > > sprintf(tempstring, "%s %f %s %f", "\pthe square of ", x, "is", (x *x)); > DrawString(tempstring); This will not work in any C which I understand. What will be put into tempstring is a null terminated string something like: \016the square of ;&91/z\234dsi 5.00000 is 25.00000 where \016 is the first character in a Pascal string of length 14, ;&91/z\234dsi represents random garbage in the memory following the string, which only ends when there happens to be a byte containing \0, and the remainder is self explanatory. "\pfoo" does not represent a C-string whose first character is '\p', it represents a Pascal string, a one-byte length followed by that many characters. Sprintf is passed an address as its argument, and it expects that address to be of a C-string. By the same token, using a format string of "\p%s %f %s %f" will also fail to work. David Palmer palmer@tybalt.caltech.edu ...rutgers!cit-vax!tybalt.caltech.edu!palmer "Every day it's the same thing--variety. I want something different."