strncpy

George Kyriazis kyriazis at ptolemy0.rdrc.rpi.edu
Mon Jan 8 07:11:45 AEST 1990


In article <1990Jan7.145719.15574 at twwells.com> bill at twwells.com (T. William Wells) writes:
>In article <KURO.90Jan6014431 at vodka.Sun.Com> kuro at Corp.Sun.Com writes:
>: I have no opinion about philosophical correctness of the current behavior of
>: strncpy() but always do:
>:       strncpy(to, from, n);
>:       to[n]=0;
>
>Maybe you meant "to[n - 1]=0;"?
>
>If the size of to is n, to[n] = 0 is illegal.
>

I think he means to[n] = 0.  strncpy() moves at most n bytes (0 to n-1), 
therefore byte n is not copied.  If you want to keep a string of length
n you better have a char array of n+1 characters..


  George Kyriazis
  kyriazis at turing.cs.rpi.edu
  kyriazis at rdrc.rpi.edu
------------------------------



More information about the Comp.lang.c mailing list