strcpy

Richard A. O'Keefe ok at quintus.UUCP
Tue Mar 22 17:14:12 AEST 1988


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 
	char *strcpy(char *dst, *src)
	    {
		int n = strlen(src) + 1;
		dst += n, src += n;
		while (--n >= 0) *--dst = *--src;
		return dst;
	    }
is clearly illegal (it copies the NUL first).



More information about the Comp.lang.c mailing list