strcpy

Dave Sill dsill at NSWC-OAS.arpa
Fri Mar 25 05:32:25 AEST 1988


>From article <793 at cresswell.quintus.UUCP>, by ok at 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 

I think you're misinterpreting that statement.  I don't think that
statement says anything about the order in which the characters are
copied or that the NUL is copied last.

As we all know, a string in C is a pointer to a list of characters
that, by convention, is terminated by a NUL character.  Given a
string, the ONLY way to determine its contents or length is to start
at the beginning and scan for the terminating NUL.  The statement
above is merely restating the NUL-terminator convention.  I don't
think it was intended to specify the actual order in which the
characters are copied.

Of course, with C's string representation, copying from beginning to
end is more efficient than finding the end of the source string and
copying backward.

=========
The opinions expressed above are mine.

"We are offended and resent it when people do not respect us;
and yet no man, deep down in his heart, has any considerable
respect for himself."
					-- Mark Twain



More information about the Comp.lang.c mailing list