Danny Epstein wrote: >John Crouch wrote: > >>Char dst[10]; >>StrNCopy(dst, "Longer than 10 bytes", 10); >>dst[9] = 0; >> > >As John Marshall said, check the docs. This code won't work with multi-byte >characters because the last statement might be zeroing the second byte of a >two-byte character. If you want your code to work with multi-byte >characters, don't let StrNCopy see the entire buffer: > > Char dst[10]; > StrNCopy(dst, "Longer than 10 bytes", 9); // save the last byte > dst[9] = 0; > >The last two lines could go in either order; they operate on adjacent, but >non-overlapping areas in memory. This works because of how StrNCopy deals >with clipping. If a two-byte character doesn't quite fit, the "extra" byte >is zeroed. > >James wrote: > >>Another method is to initialize dst[0] = '\0' and then use StrNCat instead >>of StrNCopy. >> > >That's what I do. >-- >Danny @ PalmSource > of course, this assumes a two byte character set....I was under the impression that some SJIS characters are up to 4 bytes....have I been misinformed?
BTW...any chance of a Palm device using UTF-8 character sets? Or UNICODE in general? JDB -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
