[comp.lang.c] char *strcat

karl@haddock.ISC.COM (Karl Heuer) (06/30/88)

In article <568@tuck.nott-cs.UUCP> anw@maths.nott.ac.uk (Dr A. N. Walker) writes:
>In article <2029@pt.cs.cmu.edu> jgk@speech2.cs.cmu.edu (Joe Keane) writes:
>>To be useful, strcpy and strcat should return the end of the new string.
>
>If it has to be one or t'other, don't forget that the way C works it is
>easier to find the end of a string given its beginning than to find its
>beginning given its end.

If strcpy() and strcat() return the beginning of the string, the cost of
finding the end is O(N): you make another pass through the string.  If they
return the end of the string, the cost of finding the beginning is O(1): you
already had the value, since you passed it as the first argument.  At worst,
you have to declare a temporary variable to hold it.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
Followups to comp.lang.c.