I want to write a C function that concatenates a list of
strings whose lengths are unknown at compile-time. How can I
do this efficiently?

Date: 30-Oct-91
X-Contributor: Brian Marasca <71230.1650@compuserve.com>

If you're concerned about performance, the best possible solution
would be to define a maximum string length beforehand. If you can
do that, this piece of code, submitted by Brian Marasca
(71230,1650 on Compuserve), is pretty high-performance:

#define MAXLEN 120 /* Set this to the maximum required length. */

CLIPPER cStrCat()
{
char *p, *q, *buf ;
int cx = 1, parms = _parinfo ( 0 ) ;

q = buf = _xgrab (MAXLEN + 1) ;

while (parms--)
{
p = _parc (cx++) ;
while (*p) *q++ = *p++ ;
}
*q = '\0' ; /* very important! */

_retc (buf) ;
_xfree (buf) ;
}