Skip to content

Instantly share code, notes, and snippets.

@schwern
Last active May 10, 2017
Embed
What would you like to do?
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
char * strcat_ex( const char *s, ... )
{
if ( s == NULL ) {
return NULL;
}
va_list ap;
size_t n = 0;
va_start( ap, s );
for ( const char *p = s; p != NULL; p = va_arg( ap, const char * ) )
{
n += strlen( p );
}
va_end( ap );
++n;
char *result = malloc( n );
if ( result == NULL ) {
return NULL;
}
n = 0;
va_start( ap, s );
for ( const char *p = s; p != NULL; p = va_arg( ap, const char * ) )
{
strcpy( result + n, p );
n += strlen( p );
}
va_end( ap );
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment