char *strcat(), *strcpy(), *fgets();
Joe Keane
jgk at speech2.cs.cmu.edu
Fri Jun 24 05:02:52 AEST 1988
To be useful, strcpy and strcat should return the end of the new
string. The old method is this:
(void) strcpy (base, "foo");
(void) strcat (base, "bar");
(void) strcat (base, "baz");
This can be replaced by:
end = strcpy (base, "foo");
end = strcpy (end, "bar");
(void) strcpy (end, "baz");
or more concisely:
(void) strcpy (strcpy (strcpy (base, "foo"), "bar"), "baz");
If you're concatenating many strings, remember this is linear while
the old method is quadratic. Unfortunately, there's no chance of
getting this changed. I already have a function like this, i just
don't call it strcpy.
--Joe
More information about the Comp.std.c
mailing list