日期:2014-05-16 浏览次数:20635 次
/**
* @file strjion.c
* @brief
*/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
char *strjoin(char *s, int n, ...)
{
va_list ap;
char *ptr, *arg;
int i;
size_t len;
va_start(ap, n);
ptr = s;
for (i = 0; i < n; i++) {
arg = va_arg(ap, char *);
len = strlen(arg) + 1;
memcpy(ptr, arg, len);
ptr += len;
}
va_end(ap);
return s;
}
int main(int argc, char *argv[])
{
int i;
char s[1024];
strjoin(s, 3, "123", "456", "789");
for (i = 0; i < 12; i++) {
printf("%02x ", (unsigned int)(unsigned char)s[i]);
}
printf("\n");
return 0;
}