Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!hp4nl!orcenl!bengsig From: bengsig@oracle.nl (Bjorn Engsig) Newsgroups: comp.lang.c Subject: Re: strncpy Keywords: strncpy null termination Message-ID: <1006.nlhp3@oracle.nl> Date: 21 Dec 89 14:54:10 GMT References: <11509@csli.Stanford.EDU> Reply-To: bengsig@oracle.nl (Bjorn Engsig) Organization: ORACLE Europe, The Netherlands Lines: 20 Article <11509@csli.Stanford.EDU> by poser@csli.Stanford.EDU (Bill Poser) says: | | Why is it that strncpy(3) does not null terminate ... strncpy always copies exactly n characters to the destination string by null- padding or truncating. A similar behaviour is also found in a declaration like char thing[][3] = { "a", "ab", "abc", "de" }; where each element of thing is an array of 3 characters (i.e. thing[2] is not null terminated, and puts(thing[2]) would print abcde). A way to do a limited string copy is dst[0] = 0; strncat(dst,src,n); since strncat always null-terminates. -- Bjorn Engsig, Domain: bengsig@oracle.nl, bengsig@oracle.com Path: uunet!{mcsun!orcenl,oracle}!bengsig