home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ivgate!macnet!Mike.Gleason
- From: Mike.Gleason@macnet.omahug.org (Mike Gleason)
- Newsgroups: comp.sys.mac.programmer
- Subject: RE: Re: annoying pascal strings
- Message-ID: <14.2a8aedf2@ivgate>
- Date: 12 Aug 92 10:15:34 CST
- Reply-To: mike.gleason@macnet.omahug.org
- Organization: Macnet Omaha
- Sender: news@ivgate.omahug.org (UUscan 1.10)
- Followup-To: comp.sys.mac.programmer
- Lines: 28
-
- CBC> In article <1992Aug10.132907.23439@das.harvard.edu>,
- CBC> vreddy@das.harvard.edu (Venkatesh Reddy) wrote:
- > Does anyone know of an easy way to use sprintf or something to convert
- > a number or formatted float to a pascal string? For example, I have a
- > number 45 or a number 3.4567 and I want this to go into a pascal
- > string... I can send it into a regular C string by typing
-
- > sprintf(str, "%d %f", 45, 3.4567);
-
- > but is there a way to do this to a pascal string? Thanks...
-
- CBC> sprintf(&str[1], "%d %f", 45, 3.4567);
- CBC> str[0] = strlen(&str[1]);
-
- Two ways off the top of my head:
- unsigned char str[256];
-
- sprintf((char *) str, "%d %f", 45, 3.4567);
- CtoPstr((char *) str);
-
- // or...
- *str = (unsigned char) sprintf((char *) (str + 1), "%d %f", 45, 3.4567);
-
- The printf family returns the number of characters written out, so you could
- use that instead of a costly strlen().
-
- --mg
-
-