Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!bellcore!flash!sdh From: sdh@flash.bellcore.com (Stephen D Hawley) Newsgroups: comp.sys.mac.programmer Subject: Re: Quick ThinkC String question... Keywords: THINK C STRING Message-ID: <20011@bellcore.bellcore.com> Date: 14 Feb 90 15:40:33 GMT References: <77108@tut.cis.ohio-state.edu> Sender: news@bellcore.bellcore.com Reply-To: sdh@flash.UUCP (Stephen D Hawley) Distribution: usa Organization: Bellcore, Morristown, NJ Lines: 39 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"; } Str255 is an array type. When you say "Str255 myString" you are actually saying "create an array of 256 characters named myString". When you do the assignment, you are asking Think C to do a Pascal string copy at runtime. This is undefined behavior for arrays in C. My example just does a pointer assignment. Beware that myString is a char * not an unsigned char *. If you declare it as an unsigned char * you will get a type clash, but if you don't you have to be sure to cast the first byte to an unsigned char if you use it as a length (otherwise it'll get sign extended). Steve Hawley sdh@flash.bellcore.com A noun's a special kind of word. It's ev'ry name you ever heard. I find it quite interesting, A noun's a person place or thing.