home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!stanford.edu!kronos.arc.nasa.gov!joshr
- From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
- Subject: Re: annoying pascal strings
- Message-ID: <1992Aug13.174942.18261@kronos.arc.nasa.gov>
- Sender: usenet@kronos.arc.nasa.gov (Will Edgington, wedgingt@ptolemy.arc.nasa.gov)
- Nntp-Posting-Host: kronos-arclan.arc.nasa.gov
- Organization: NASA/ARC Information Sciences Division
- References: <1992Aug10.132907.23439@das.harvard.edu> <zben-100892215906@zben-mac-ii.umd.edu>
- Date: Thu, 13 Aug 1992 17:49:42 GMT
- Lines: 72
-
- In article <zben-100892215906@zben-mac-ii.umd.edu> zben@ni.umd.edu (Charles B. Cranston) writes:
- >In article <1992Aug10.132907.23439@das.harvard.edu>,
- >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...
- >
- >sprintf(&str[1], "%d %f", 45, 3.4567);
- >str[0] = strlen(&str[1]);
- >
- >Or something close to it, you erect a C string at one byte into the
- >memory area then manually store the length byte. No, I won't answer
- >your other question till you put in carriage returns at reasonable
- >line boundaries...
- >
- >zben@ni.umd.edu -KA3ZDF
-
- Some common C functions: these modify the string in place.
- ------------
- here is header
- char * CToPStr(char *aCStr);
- char * PToCStr(char *aPStr);
-
- =
- ------------
- here is source
- ------------
-
-
-
- #include "StrFuncs.h"
- #include <string.h>
- #include <Global.h>
-
-
- char * CToPStr(char *aCStr)
- {
- long i, len;
- len = strlen(aCStr);
- for (i=len; i>0; i--)
- aCStr[i] = aCStr[i-1];
-
- aCStr[0] = Min(255, len);
- return aCStr;
- }
-
-
- char *PToCStr(char *aPStr)
- {
- long i, len;
- len = *aPStr;
- for (i=0; i<len; i++)
- aPStr[i] = aPStr[i+1];
- aPStr[len] = '\0';
- return aPStr;
- }
-
-
-
-
-
- --
- ----------------------------------
- #include <std/disclaimer.h> Josh Rabinowitz, Mac TCL programmer
- joshr@kronos.arc.nasa.gov
- "'I see', said the blind carpenter, as he picked up his hammer and saw".
-