Last active
May 10, 2017 23:00
-
-
Save schwern/ccaa8d4d2868a520592e49dabc5d310d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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