Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!psuvax1!psuvm!cxt105 From: CXT105@PSUVM.BITNET (Christopher Tate) Newsgroups: comp.sys.mac.programmer Subject: Re: ARRGH (Strings and things) Message-ID: <89300.054241CXT105@PSUVM.BITNET> Date: 27 Oct 89 09:42:41 GMT References: <16004@netnews.upenn.edu> Distribution: usa Organization: Penn State University Lines: 52 In article <16004@netnews.upenn.edu>, parnes@eniac.seas.upenn.edu (Gary Parnes) says: >So what's wrong with this? > >Str255 myString; >StringHandle mystringhandle; > >myString=**mystringhandle; What you're trying to do here, in actuality, is copy every element of the Str255 you find with **mystringhandle into the Str255 variable called myString. You can't do this, for the same reason that you can't simply assign two arrays to be equal: C doesn't let you do it. That's why the compiler gives you an "illegal operation on array" message. Since you're dealing with Pascal strings, the copying gets a little messy. What I do is copy the length byte, then use it as a counter as I copy the string from **mystringhandle into myString, thus: StringHandle mystringhandle; Str255 myString; char *toPtr, *fromPtr; int i; fromPtr = (char *)(*mystringhandle); /* point to the first char */ toPtr = (char *) &myString; /* of both strings */ *toPtr = *fromPtr; /* copy the length byte */ i = *fromPtr; /* set up the counter */ toPtr++; fromPtr++; /* point to the actual string data */ for (;i>0;i--) /* do this for each character in the string.... */ { *toPtr = *fromPtr; /* copy a byte of the string */ toPtr++; fromPtr++; /* move along one byte */ } This fragment copies the contents of the string accessed through mystringhandle into the Str255 variable myString. (At least, that's what I *think* it does; I wrote it off the cuff and it may be wrong :-). I wrote out all the pointer incrementing explicitly to help you see what's going on. If you're a new programmer, you probably have the same problem with C that I had: reading it ("C" stands for "Cryptic"). Anyway, you'll probably hear different ways of doing it, but that's what springs to my mind. Hope it helps. ------- Christopher Tate | "Oh wow: not only is 57 | prime, but it's also Bitnet: cxt105@psuvm | divisible by three!" Uucp: ...!psuvax1!psuvm.bitnet!cxt105 | Internet: cxt105@psuvm.psu.edu | - a very sincere math major