Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!amdahl!nsc!voder!apple!rmh From: rmh@Apple.COM (Rick Holzgrafe) Newsgroups: comp.sys.mac.programmer Subject: Re: C to Pascal strings Message-ID: <7537@apple.Apple.Com> Date: 2 Mar 88 19:46:22 GMT References: <4619@pucc.Princeton.EDU> Reply-To: rmh@apple.UUCP (Rick Holzgrafe) Organization: Apple Computer, Inc. Lines: 40 In article <4619@pucc.Princeton.EDU> MJSCHMEL@pucc.Princeton.EDU writes: >If someone could please provide a working example of C to Pascal string >conversion in MPW I would be eternally grateful. > >Let's get comp.sys.mac.programmer off to a good start and give me an >answer! (This posting was completely ignored on comp.sys.mac) > >============================================================================== >comes around Mike Schmelzer MJSCHMEL@PUCC.Princeton.Edu what goes around >============================================================================== Completely ignored? Gosh - for once, everyone must have done like I did, and assumed someone else would answer. Ok, here it is: char buf[] = "Fee fie foe fum"; c2pstr (buf); Buf now contains "\17Fee fie foe fum" with no terminating null byte. To convert it back to a C string: p2cstr (buf); These conversions work "in place": your original string is munged into the new format. This works, of course, since both pascal and C strings require the same amount of space: one character extra, either at the end for the null byte in C, or at the beginning for the length byte in Pascal. Judging from the declarations, these routines also return a pointer to the same string you pass them. This is so that you can use these calls as parameters to some other call, such as: printf ("%s\n", p2cstr (a_pascal_string)); My first examples above ignored the returned value. ========================================================================== Rick Holzgrafe | {sun,voder,nsc,mtxinu,dual}!apple!rmh Communications Software Engineer | AppleLink HOLZGRAFE1 rmh@apple.com Apple Computer, Inc. | "All opinions expressed are mine, and 20525 Mariani Ave. MS: 27-Y | do not necessarily represent those of Cupertino, CA 95014 | my employer, Apple Computer Inc."