On Sun, 26 May 2002, Keith Rollin wrote:
> Let's also take a look at the following that you posted:
>
> >   // locate a space
> >   p = StrChr(sentence, ' ');
> >
> >   if (p)
> >     // found a space, so copy the word
> >     StrNCopy(word, sentence, (p - sentence));
>
> This is questionable, not only because StrNCopy's definition has
> changed in practically every release of the OS, but because even when
> using the standard definition of strncpy, you'll have a termination
> problem.  You are guaranteeing that the result will not be properly
> terminated with a NUL.

  since when has it changed practically every release? :P

> >   if (p)
      {
> >     // found a space, so copy the word
> >     StrNCopy(word, sentence, (p - sentence));
        word[(p-sentence)] = '\0';
      }

  would do the trick.. :) it has always been my interpretation that
  SrtNCopy() copies n chars, unless, the source string is shorter
  in which it'll copy the length of the source string only. maybe
  i missed something with new versions of the os as they came out :P

  to avoid any confusion, one could also do a MemSet() on the
  word string prior to doing any of this :P thats pretty much
  standard programming practice for me.. allocate buffer - memset
  to 0 - use it - free it. :P same goes for variables.. initialize
  to 0 (or default) prior to use..

// az
[EMAIL PROTECTED]
http://www.ardiri.com/


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

Reply via email to