Article View: comp.sys.mac
Article #7044Re: Need help in THINK C
From: Gary Morris
Date: Wed, 25 Oct 1989 00:14
Date: Wed, 25 Oct 1989 00:14
38 lines
2246 bytes
2246 bytes
In article <2393@eagle.wesleyan.edu>, rsilverman@eagle.wesleyan.edu writes:
> In article <15790@netnews.upenn.edu>, parnes@eniac.seas.upenn.edu
> (Gary Parnes) writes:
> > I have a problem... How do you copy a string from a dialog EditText item
> > into a character array?
>
> ...In this case, the problem is probably this: the text for all text items
> in a dialog is kept in one big TextEdit record, managed by the Dialog
> Manager. Use the GetIText (I think that's it) routine to retrieve the text
> from an item. Remember, it will return it as a Pascal string, so you'll
> have to add the NUL yourself.
Not only do you need to add a NUL (0) at the end, you must skip over the
length byte at the beginning of Pascal strings. If you have a Pascal string
Pstr, you can pass it to a C routine, like so:
Pstr[ Pstr[0] ] = (char) 0; /* add the NUL on the end */
strcpy( DestStr, &Pstr[1] ); /* copy string with first character */
Or if you don't want to modify the source string by adding a NUL on the end
you can use strncpy and specify the length to copy:
strncpy( DestStr, &Pstr[1], (int) Pstr[0] );
Or with Think C you can use the supplied routine "PtoCstr" to convert a
string from Pascal format to C format.
Disclaimer: I haven't actually tried these examples and I'm new to using C
on the Mac (I prefer TeleSoft Ada). If these examples don't work I will
repair or replace them or refund your purchase price at my option.
--GaryM
--
Gary Morris {uunet,ucsd}!telesoft!garym TeleSoft
N6FRT garym@telesoft.com San Diego, CA, USA
ASEL garym@nynashamn.telelogic.se +1 619 457-2700
"If something is worth doing, it's worth doing right."
Technical Details
Message-ID:
<573@telesoft.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ucsd!telesoft!garymReferences:
<5306@lindy.Stanford.EDU> <15790@netnews.upenn.edu> <2393@eagle.wesleyan.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ucsd!telesoft!garym From: garym@telesoft.com (Gary Morris @nova) Newsgroups: comp.sys.mac Subject: Re: Need help in THINK C Summary: use PtoCstr to convert strings Message-ID: <573@telesoft.com> Date: 25 Oct 89 00:14:30 GMT References: <5306@lindy.Stanford.EDU> <15790@netnews.upenn.edu> <2393@eagle.wesleyan.edu> Followup-To: comp.sys.mac.programming Organization: TeleSoft, San Diego, CA. Lines: 38