Path: utzoo!mnetor!motto!dave From: dave@motto.UUCP (David Brown) Newsgroups: comp.lang.c Subject: Re: strncpy Message-ID: <80@motto.UUCP> Date: 24 Jan 90 14:25:19 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> <11881@csli.Stanford.EDU> <4128@helios.TAMU.EDU> Reply-To: dave@motto.UUCP (David Brown) Lines: 25 In article <4128@helios.TAMU.EDU> john@stat.tamu.edu (John S. Price) writes: >Every manual I read says this: >"... If the string pointed to by the source has fewer than count >characters, nulls are added to the end of dest until count characters >have been copied." -- C - The Complete Reference. > >"... strncpy(s,t,n) copy exactly n characters; null pad if necessary" > -- Unix Programming Environment > We found this useful when dealing with the keys of ISAM files under VMS. If the key was a C string, we used strncpy() to copy it rather than strcpy(). This guaranteed that the bytes following the '\0' were all zeroes. This was important because the filesystem compared all bytes of the key. If we had used strcpy(), two keys which were the same string value could be different as far as the filesystem was concerned, because of garbage following the '\0'. ----------------------------------------------------------------------------- | David C. Brown | uunet!mnetor!motto!dave | | Motorola Canada, Ltd. | 416-499-1441 ext 3708 | | Communications Division | "Of course I'm above average! Who isn't?" | -----------------------------------------------------------------------------