[net.unix-wizards] Wanted: String Concatenation

dmy (01/12/83)

Function Wanted: strcatx()

Does anyone have a C function like strcat which takes an arbitrary number of
arguments?  To be specific:  strcatx(dest,src1,src2,src3,....,srcn,0)
concatenates all the source strings consecutively to the end of dest.  Any of
the srci can point to an empty string; the NULL terminator is of course
different from a non-null pointer to an empty string.

--dmy-- (harpo!seismo!dmy) (Laziness --> Repeat Request)

jfw (01/14/83)

Such a function would probably depend on the particular machine you are running
on (witness the hairiness of printf).
Here is a version for PDP-11 V7's (this is being written off the top of
my pointy little head, so I don't entirely guarantee it, though I have
just tested it, and it seems to work):

char *strcatx(dest,srcs)
char *dest;
{
	char **srcn = &srcs,*p = dest;

	/* advance p to end of dest. string */

	while (*p++)
		continue;
	p--;

	/* now, start catting each pointer on stack */
	for ( ; *srcn != 0; srcn++ ) {
		/* strcpy(p,**srcn) */
		while (*p++ = *(*srcn)++)
			continue;
		p--;
	}
	return dest;
}

- John Woods, ...!genradbo!mitccc!jfw, JFW%MIT-CCC@MIT-MC

PS: It took about 15 minutes to write, test, and debug.