home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / mac / programm / 13945 < prev    next >
Encoding:
Text File  |  1992-08-13  |  2.3 KB  |  85 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!stanford.edu!kronos.arc.nasa.gov!joshr
  3. From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
  4. Subject: Re: annoying pascal strings
  5. Message-ID: <1992Aug13.174942.18261@kronos.arc.nasa.gov>
  6. Sender: usenet@kronos.arc.nasa.gov (Will Edgington, wedgingt@ptolemy.arc.nasa.gov)
  7. Nntp-Posting-Host: kronos-arclan.arc.nasa.gov
  8. Organization: NASA/ARC Information Sciences Division
  9. References: <1992Aug10.132907.23439@das.harvard.edu> <zben-100892215906@zben-mac-ii.umd.edu>
  10. Date: Thu, 13 Aug 1992 17:49:42 GMT
  11. Lines: 72
  12.  
  13. In article <zben-100892215906@zben-mac-ii.umd.edu> zben@ni.umd.edu (Charles B. Cranston) writes:
  14. >In article <1992Aug10.132907.23439@das.harvard.edu>,
  15. >vreddy@das.harvard.edu (Venkatesh Reddy) wrote:
  16. >
  17. >> Does anyone know of an easy way to use sprintf or something to convert
  18. >> a number or formatted float to a pascal string? For example, I have a
  19. >> number 45 or a number 3.4567 and I want this to go into a pascal
  20. >> string... I can send it into a regular C string by typing
  21. >
  22. >> sprintf(str, "%d %f", 45, 3.4567);
  23. >
  24. >> but is there a way to do this to a pascal string? Thanks...
  25. >
  26. >sprintf(&str[1], "%d %f", 45, 3.4567);
  27. >str[0] = strlen(&str[1]);
  28. >
  29. >Or something close to it, you erect a C string at one byte into the
  30. >memory area then manually store the length byte.  No, I won't answer
  31. >your other question till you put in carriage returns at reasonable
  32. >line boundaries...
  33. >
  34. >zben@ni.umd.edu     -KA3ZDF
  35.  
  36. Some common C functions: these modify the string in place.
  37. ------------
  38. here is header
  39. char * CToPStr(char *aCStr);
  40. char * PToCStr(char *aPStr);
  41.  
  42. =
  43. ------------
  44. here is source
  45. ------------
  46.  
  47.  
  48.  
  49. #include "StrFuncs.h"
  50. #include <string.h>
  51. #include <Global.h>
  52.  
  53.  
  54. char * CToPStr(char *aCStr)
  55. {
  56.    long i, len;
  57.    len = strlen(aCStr);
  58.    for (i=len; i>0; i--) 
  59.       aCStr[i] = aCStr[i-1];
  60.       
  61.    aCStr[0] = Min(255, len);
  62.    return aCStr;
  63. }
  64.  
  65.  
  66. char *PToCStr(char *aPStr)
  67. {
  68.    long i, len;
  69.    len = *aPStr;
  70.    for (i=0; i<len; i++) 
  71.       aPStr[i] = aPStr[i+1];
  72.    aPStr[len] = '\0';
  73.    return aPStr;
  74. }
  75.  
  76.     
  77.  
  78.  
  79.                           
  80. -- 
  81. ----------------------------------
  82. #include <std/disclaimer.h>     Josh Rabinowitz, Mac TCL programmer
  83. joshr@kronos.arc.nasa.gov
  84. "'I see', said the blind carpenter, as he picked up his hammer and saw".
  85.