One method: Make the destination string 1 char longer then the max # you will copy. You should always get the NULL at the end. Just to be on the safe side, it wouldn't hurt to manually assign the last char in the destination string to NULL every time.
char dest[11]; StrNCopy(dest,"longer than 10 bytes",10); dest[10] = NULL; /// Just to be safe ----- Original Message ----- From: "John Crouch" <[EMAIL PROTECTED]> Newsgroups: palm-dev-forum To: "Palm Developer Forum" <[EMAIL PROTECTED]> Sent: Thursday, April 04, 2002 10:29 AM Subject: StrNCopy() > I want to use StrNCopy() with a single byte character string. I understand > that if the src string is less than n-characters in length that the dst > string gets padded to the right with NULLs. This is good. But if the src > is n-characters or longer then no NULL is appended to the dst string and you > don't have a NULL terminated string anymore. > > What is the best way to work around this? Simply place a NULL at the end of > the destination string every time you use this function? Like this: > > Char dst[10]; > StrNCopy(dst, "Longer than 10 bytes", 10); // too long so no NULL us > appended > dst[9] = 0; // always NULL the last char whether we need to or not. > > -- or -- > > Char dst[10]; > StrNCopy(dst, "Hello", 10); // padded with NULLs > dst[9] = 0; // always NULL the last char whether we need to or not. > > > What if I want to make sure this is Multi-Byte Character friendly? I have > no experience in that area but I am always up for making my code forward > compatible. > > Thanks. > > > > > -- > For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ > -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
