Path: utzoo!mnetor!uunet!husc6!mailrus!nrl-cmf!cmcl2!brl-adm!adm!dsill@NSWC-OAS.arpa From: dsill@NSWC-OAS.arpa (Dave Sill) Newsgroups: comp.lang.c Subject: Re: strcpy Message-ID: <12636@brl-adm.ARPA> Date: 25 Mar 88 14:39:55 GMT Sender: news@brl-adm.ARPA Lines: 42 In article <18488@think.UUCP> Barry Margolin writes: >Will you guys stop playing word games, and think about what that >sentence was really intended to mean? I think the point of the >"stopping after the NUL" phrase is that it doesn't copy any characters >after the NUL. Thus, if you have > > char [10] dest, source; > strcpy (source, "abcdefghi"); > strcpy (dest, "123456789"); > source [3] = '\0'; > strcpy (dest, source); > >the resulting contents of dest will be > > 'a' 'b' 'c' '\0' '5' '6' '7' '7' '9' '\0' > >i.e. the last six characters are not affected. I don't think that that's guaranteed, or even implied by that sentence. I would expect the contents of `dest' to be: 'a' 'b' 'c' '\0' ? ? ? ? ? ? where `?' may or may not be the same character that was in that position before the call to strcpy. I could imagine an implementation that would null-out the destination string if it was longer than the source. ANSI describes `strcpy' a little differently: "The `strcpy' function copies the string pointed to by `s2' (including the terminating null character) into the array pointed to by `s1'. If copying takes place between objects that overlap, the behavior is undefined." There is nothing said about the order in which the copying takes place, or the contents of the destination string past the null character. ========= The opinions expressed above are mine. "The wretched reflect either too much or too little." -- Publilius Syrus