home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / mac / programm / 13962 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  1.3 KB

  1. Path: sparky!uunet!ivgate!macnet!Mike.Gleason
  2. From: Mike.Gleason@macnet.omahug.org (Mike Gleason)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: RE: Re: annoying pascal strings
  5. Message-ID: <14.2a8aedf2@ivgate>
  6. Date: 12 Aug 92 10:15:34 CST
  7. Reply-To: mike.gleason@macnet.omahug.org
  8. Organization: Macnet Omaha
  9. Sender: news@ivgate.omahug.org (UUscan 1.10)
  10. Followup-To: comp.sys.mac.programmer
  11. Lines: 28
  12.  
  13. CBC> In article <1992Aug10.132907.23439@das.harvard.edu>,
  14. CBC> vreddy@das.harvard.edu (Venkatesh Reddy) wrote:
  15. > Does anyone know of an easy way to use sprintf or something to convert
  16. > a number or formatted float to a pascal string? For example, I have a
  17. > number 45 or a number 3.4567 and I want this to go into a pascal
  18. > string... I can send it into a regular C string by typing
  19.  
  20. > sprintf(str, "%d %f", 45, 3.4567);
  21.  
  22. > but is there a way to do this to a pascal string? Thanks...
  23.  
  24. CBC> sprintf(&str[1], "%d %f", 45, 3.4567);
  25. CBC> str[0] = strlen(&str[1]);
  26.  
  27. Two ways off the top of my head:
  28.     unsigned char str[256];
  29.     
  30.     sprintf((char *) str, "%d %f", 45, 3.4567);
  31.     CtoPstr((char *) str);
  32.  
  33.     // or...
  34.     *str = (unsigned char) sprintf((char *) (str + 1), "%d %f", 45, 3.4567);
  35.  
  36. The printf family returns the number of characters written out, so you could
  37. use that instead of a costly strlen().
  38.  
  39. --mg
  40.  
  41.