home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / mac / programm / 13961 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  1.4 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: <10.2a8aedee@ivgate>
  6. Date: 12 Aug 92 10:02:31 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: 29
  12.  
  13. SR> This was a discussion of how to sprintf to a Pascal string...
  14. SR> In article <25403@dog.ee.lbl.gov> sichase@csa2.lbl.gov writes:
  15. >In article <zben-100892215906@zben-mac-ii.umd.edu>, zben@ni.umd.edu (Charles
  16.  
  17. SR> B. Cranston) writes...
  18. >>In article <1992Aug10.132907.23439@das.harvard.edu>,
  19. >>vreddy@das.harvard.edu (Venkatesh Reddy) wrote:
  20. >>
  21. >>sprintf(&str[1], "%d %f", 45, 3.4567);
  22. >>str[0] = strlen(&str[1]);
  23. >
  24. >That's the hard way.  The easy way is:
  25. >sprintf(str, "\p%d %f", 45, 3.4567);
  26. >Think C recognizes the \p control character and takes care of the rest.
  27.  
  28. SR> Actually, Charles's solution doesn't work.  Think C translates the
  29. SR> string into "\005%d %f" and then treats it as a C string.  The result
  30. SR> from the sprintf would be "\00545 3.456700" which is the same as "\p45
  31. SR> 3.", NOT the result we'd want.  I'd go with Venkatesh's solution and
  32. SR> maybe check for resulting strings longer than 255 characters.
  33. SR> Stepan
  34.  
  35. Could do either of these:
  36. sprintf(str, "%d %f", 45, 3.4567);
  37. CtoPstr(str);
  38.  
  39. or:
  40. unsigned char str[256];
  41.  
  42.