Last active
December 30, 2015 23:59
-
-
Save larzconwell/7904573 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 <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