Michel,

you can copy a 0-terminated string with StrCopy (it actually only works for such a string). StrCopy will add a 0-byte at the end of the destination string. StrNCopy (the safe version of StrCopy) will not add a 0-byte to the end of destionation, if (and only if) the space for the destination was not enough to copy the whole string + the 0-byte. Therefore if you use StrNCopy use as parameter for the destination size one byte less than the real size is. Then you can add 0-byte as last byte of your destination in any case.

dest[an array big enough for the string + 1 byte]
// this will add a 0-byte at position src[StrLen(dest)]
StrCopy(dest, src);
// but can overwrite your destination, if it wasn't big enough

// this will not overwrite your destination, but it will maybe not add a // 0-byte at the end
StrNCopy(dest, src, sizeof(dest));
// therefore do it on your own
dest[sizeof(dest)-1] = 0;


Henk

Michel.P wrote:
Hi Henk,

I thought one couldn't copy a null string using
StrCopy(): I tried that before posting my question
(but usting '\0' instead of "\0") and it gave me an
error, and I believe someone in another post said that
you can't StrCopy() null....?


--- Henk Jonas <[EMAIL PROTECTED]> wrote:

Michel,

if you know its 0-terminated, you can do a StrCopy,
add a "\0" and another StrCopy + "\0" from StrLen()+1 as well. The
thing about MemSet is if you have a chunk of memory (getting from
MemLock or whatever) and you don't know if it is initialized with "\0" at the
beginning, you better do a MemSet with 0x00 to ensure you will have
a 0-terminated string, regardless what you do.

Henk

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus � Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



--
-------------------------------------------------------------------------
[EMAIL PROTECTED]                                       www.metaviewsoft.de

<A HREF="http://www.handango.com/PlatformTopSoftware.jsp?authorId=95946";>
<IMG SRC="http://user.cs.tu-berlin.de/~jonash/werbung.jpg";></A>
-------------------------------------------------------------------------


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

Reply via email to