Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!crdgw1!crdos1!davidsen From: davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: strncpy Message-ID: <2034@crdos1.crd.ge.COM> Date: 23 Jan 90 13:39:59 GMT References: <11527@csli.Stanford.EDU> <000003Q@cdis-1.UUCP> <11616@csli.Stanford.EDU> <48314938.f69e@phobos.UUCP> <11864@csli.Stanford.EDU> <25BC3A32.3F5B@marob.masa.com> Reply-To: davidsen@crdos1.crd.ge.com (bill davidsen) Organization: GE Corp R&D Center, Schenectady NY Lines: 19 In article <25BC3A32.3F5B@marob.masa.com> daveh@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@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen) "Stupidity, like virtue, is its own reward" -me