Skip to content

Instantly share code, notes, and snippets.

@larzconwell
Last active December 30, 2015 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larzconwell/7904573 to your computer and use it in GitHub Desktop.
Save larzconwell/7904573 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char *strs[] = {"example", "another", "hi"};
static int strc = 3;
int main(void) {
int i = 0;
int size = 1;
for (; i < strc; i++) {
size += strlen(strs[i]) + 1;
}
char *args = malloc(size);
if (NULL == args) {
fprintf(stderr, "Unable to allocate memory");
return 1;
}
strcpy(args, "\0");
for (i = 0; i < strc; i++) {
strcat(args, strs[i]);
strcat(args, " ");
}
printf("%s\n", args);
free(args);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment