Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!apple!oracle!news From: omullarn@oracle.oracle.com (Oliver Mullarney) Newsgroups: comp.sys.mac.programmer Subject: Re: Quick ThinkC String question... Keywords: THINK C STRING Message-ID: <1990Feb14.210352.28118@oracle.com> Date: 14 Feb 90 21:03:52 GMT References: <77108@tut.cis.ohio-state.edu> <20011@bellcore.bellcore.com> Reply-To: omullarn@oracle.com (Oliver Mullarney) Distribution: usa Organization: Oracle Corporation, Belmont, CA Lines: 49 In article <20011@bellcore.bellcore.com> sdh@flash.UUCP (Stephen D Hawley) writes: >In article <77108@tut.cis.ohio-state.edu> writes: >>Hi, >> >>I'm having a problem getting ThinkC to accept the following: >>procedureX() >>{ >> Str255 myString; >> >> myString = "\pExample string"; >>} > >Try: > >procedureX() >{ > char *myString; > > myString = "\pExample string"; >} > This is just a little dubious; no space is being allocated anywhere, so this should not be used in a general case. It will work for the given situation, but not once you drop up one level on the stack from where the assignment is made (literals are defined on the stack, right?). What I would do is: procedureX() { char *myString = (char *)malloc(256); /* can index 0 to 255 */ strcpy(myString,"Example string"); c2pstr(myString); /* effectively turns it into an Str255 */ ... p2cstr(myString); /* unnecessary, but why not be tidy :-) */ free (myString); } This is a little more general, and safe. Oliver | Oliver Mullarney | "Death wears a big hat, | | Oracle Corporation | 'cos he's a big bloke" | | omullarn@oracle.com | Tokyo Storm Warning, Elvis Costello | --------------- "Universally acknowledged to work just fine" ----------------