[comp.sys.mac] Why doesn't this work?

steig@batcomputer.UUCP (06/15/87)

I'm just learning C, so if this is obvious, then please don't flame on me.

The following is written in Lightspeed C:

/*Given these declarations,*/
char *Cstring,*copyofCstring;
Str255 Pstring;

/*This works*/
Cstring=PtoCstr(Pstring);
stpcpy(copyofCstring,Cstring);

/*This doesn't*/
stpcpy(copyofCstring,PtoCstr(Pstring);

/*Why?*/
-- 
|Mark J. Steiglitz          |Bitnet: steig@crnlthry, araj@crnlvax5            |
|USnail: 66 Steiglitz Road  |Arpanet: steig@tcgould.tn.cornell.edu            |
|        Liberty, NY  12754 |         araj@vax5.ccs.cornell.edu               |
|                           |Usenet: steig@batcomputer.tn.cornell.edu.uucp    |

clubmac@runx.ips.oz (Macintosh Users Group) (06/20/87)

In article <1376@batcomputer.tn.cornell.edu> steig@tcgould.tn.cornell.edu (Mark J. Steiglitz) writes:
>
>/*This works*/
>Cstring=PtoCstr(Pstring);
>stpcpy(copyofCstring,Cstring);
>
>/*This doesn't*/
>stpcpy(copyofCstring,PtoCstr(Pstring);
>
>/*Why?*/

This was an annoying bug in the MacTraps released with versions of LSC before
2.01, where PtoCstr/CtoPstr didn't return a pointer to the string as one would
expect, making it necessary to declare a dummy Str255.

THINK clearly states on page 13-88 of the LSC Manual...

"However, this function also returns a pointer to the converted string."

And with LSC 2.01, PtoCstr & CtoPstr now returns a pointer, per 13-88.

I just found this out, because I had trouble with {P,C}to{C,P}str when using
LSC 1.02, I simply forgot to try it out when I received 2.01 !! So, I ran
the following thru LSC just now, and had no problems.

#include <strings.h>
#include <pascal.h>

#define TestPString "\pThis is a test string."

main()
{
	char	s[256];
	
	/*This works*/

	stpcpy(s,TestPString);
	PtoCstr(s);
	printf("1: %s\n",s);

	/* This does too! */

	printf("2: %s\n",PtoCstr(TestPString));
}


Hope that helps,
		Jason Haines

Club Mac Macintosh Users Group, Sydney, Australia
Snail:     Box 213, Holme Building, Sydney University, NSW, 2006, Australia
ACSnet:    clubmac@runx.ips.oz	   ARPA:   clubmac%runx.ips.oz@seismo.css.gov
UUCP:{enea,hplabs,mcvax,prlb2,seismo,ubc-vision,ukc}!munnari!runx.ips.oz!clubmac