On Wed, Oct 01, 2003 at 10:27:06AM -0700, Kerry Twibell wrote:

> I've been using the function "MemPtrNew(StrLen(charsP)) - this way, I
> don't allocate too much or too little memory. Is this the correct way
> to allocate memory for Char strings?

No. You need to find a good book that explains C strings to you. 

You need to allocate enough memory to hold the entire string, which is the
length of the string, plus one byte to hold the NUL termination character:

 MemPtrNew(StrLen(c) + 1);

> I've tried "MemPtrNew(sizeof(charsP)),"

This will allocate 4 bytes (charsP is a pointer, which is 4 bytes on
m68k).

> "MemPtrnew(sizeof(*charsP))" and 

This will allocate 1 byte (*charsP is a char, which is 1 byte).

> "MemPtrNew(*charsP)," but all seem to fail.

This will allocate an undetermined number of bytes, from 0 to 255,
depending on what the first character is in the string. If the string
was "A bug", then it would allocate 65 bytes (ascii A == 65).

-- 
Dave Carrigan
Seattle, WA, USA
[EMAIL PROTECTED] | http://www.rudedog.org/ | ICQ:161669680
UNIX-Apache-Perl-Linux-Firewalls-LDAP-C-C++-DNS-PalmOS-PostgreSQL-MySQL

Dave is currently listening to Lords of the New Church - My Kingdom Come (The Method 
To Our Madness)

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to