Path: utzoo!mnetor!uunet!husc6!think!barmar From: barmar@think.COM (Barry Margolin) Newsgroups: comp.lang.c Subject: Re: strcpy Message-ID: <18488@think.UUCP> Date: 24 Mar 88 16:26:28 GMT References: <793@cresswell.quintus.UUCP> <545@anuck.UUCP> <810@cresswell.quintus.UUCP> Sender: usenet@think.UUCP Reply-To: barmar@fafnir.think.com.UUCP (Barry Margolin) Organization: Thinking Machines Corporation, Cambridge, MA Lines: 46 In article <810@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: >In article <545@anuck.UUCP>, jrl@anuck.UUCP (j.r.lupien) writes: >> From article <793@cresswell.quintus.UUCP>, by ok@quintus.UUCP (Richard A. O'Keefe): >> > The UNIX manuals say of strcpy(s1, s2) that it >> > "copies s2 to s1, stopping after the null character has been copied." >> > While they doesn't strictly speaking say anything about the order in which >> > the other characters are copied, they _do_ say that the NUL character must >> > be copied last, so >> Stopping after something occurs, as with "after the NULL has been copied" >> does NOT equate, as you go on to assume, to "nothing will be done after >> the NULL[*] is copied. The function will return immediately." > >That's not what I assumed. The function could well compute factorial 5000. >So what? The manual says that COPYING stops after the NUL character has >been copied. So whatever strcpy does after copying NUL, either it doesn't >copy any part of s2 to s1, or the manual entry is just plain wrong (which >would not be unprecedented). The point of my message was that AT&T >documentation provides some warrant for expecting a left-to-right order >rather than some other order. 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. Programmers accustomed to some other programming languages might have expected all the declared contents of the string to be copied, and this phrase serves as a reminder that string functions don't know about declared array dimensions, all they know is that '\0' ends a string. Barry Margolin Thinking Machines Corp. barmar@think.com uunet!think!barmar