strncpy

Wm E Davidsen Jr davidsen at crdos1.crd.ge.COM
Wed Jan 24 00:39:59 AEST 1990


In article <25BC3A32.3F5B at marob.masa.com> daveh at marob.masa.com (Dave Hammond) writes:

| From the Xenix manual page for string(S):
| 
| char *strncpy(S1,S2,N)
| ...
| strncpy copies exactly N characters, truncating or null-padding S2; the
| target may not be null-terminated if the length of S2 is N or more.
| ...

  Regardless of what the manual says, it does not seem to work that way.
The copy is *at most* N characters, but will stop is a null byte is
encountered. You can verify this by placing data after the null byte in
the source string and checking that it is not copied.

  I believe the procedure which functions as described is memcpy().
-- 
bill davidsen	(davidsen at crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen)
            "Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list