

*** Listing 4 ***

#include <stdio.h>
#include <stdarg.h>
#include <string.h>

/*
 * Concatenate copies of a variable number strings into
 * s1.  The list of strings must be terminated by NULL.  
 * concat returns s1.
 */
char *concat(char *s1, ...)
	{
	char *s = s1;
	const char *t;
	va_list ap;

	va_start(ap, s1);
	while ((t = va_arg(ap, const char *)) != NULL)
		{
		strcpy(s, t);
		s += strlen(s);
		}
	va_end(ap);
	return s1;
	}

int main(void)
	{
	char s[100];
	
	puts(concat(s, "This ", "is ", "great!", NULL));
	return 0;
	}

