Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!uxh.cso.uiuc.edu!johnsone From: johnsone@uxh.cso.uiuc.edu Newsgroups: comp.sys.mac.programmer Subject: (THINK) C string/Str255 help? Message-ID: <53100015@uxh.cso.uiuc.edu> Date: 15 Apr 90 00:38:57 GMT Lines: 63 Nf-ID: #N:uxh.cso.uiuc.edu:53100015:000:2695 Nf-From: uxh.cso.uiuc.edu!johnsone Apr 14 00:57:00 1990 Hi. I'm very new to the Mac programming scene and my C is a bit rusty, so I have been a bit confused. Here is a section of code that I have been working on (THINK C v4.0) and I don't understand exactly what's happening. The exact strings in the STR# resource that this reads in are irrelevant (they are about 20 characters long, if that makes any difference). > main() > {Str255 myString; > /* initialize toolbox, quickdraw, etc.; set up a window to draw in */ > GetIndString( &myString, 400, 1 ); /* Location (1) */ > MoveTo( 0, 20 ); > DrawString( &myString ); /* Location (2) */ > MyChangeString( myString ); /* Location (3) */ > MoveTo( 0, 60 ); > DrawString( myString ); } /* Location (4) */ > > MyChangeString( aString ) > Str255 aString; > { GetIndString( aString, 400, 2 ); /* Location (5) */ > MoveTo( 0, 40 ); > DrawString( aString ); } /* Location (6) */ In the first call to GetIndString (1), it will accept the statement either with or without the '&', and the first DrawString (2) then draws the correct string, again with or without the '&'. It doesn't seem to matter whether MyChangeString is called with the '&' before myString or without it (3) In the subroutine MyChangeString, in order for that DrawString to output the correct string (6), the '&' must be in both (or neither) of the GetIndString statement (5) and the DrawString statement (6). But if the '&' is in both (5) and (6), then the final DrawString (4) draws a corrupted string, whether or not a '&' is there. My confusion lies especially in the fact that since the GetIndString is defined in Inside Mac (I-468) as PRODEDURE GetIndString (VAR string: Str255, [etc.] then (according to THINK C v4.0 manual page 120) the string should be passed _with_ the '&' to send a pointer. But then why does it not matter sometimes if the '&' is there? Isn't Str255 a pointer anyway? Is it true to say, " Str255 = char * " ? Similarly, how can one copy one Str255 to another? Is it necessary to use a function like strcpy? Also, when I write my C subroutines, how should I pass Str255's when I want to "pass by value"? and how should the routine (or function) be declared? What if I want to "pass by reference" (that is, like the Pascal VAR pass)? If anyone has some examples of code that demonstrate this, I would greatly appreciate seeing it. Thanks much. Erik A. Johnson, Graduate Student \ Internet: johnsone@uxh.cso.uiuc.edu Aeronautical & Astronautical Engineering \ University of Illinois at Urbana-Champaign \