Skip to content

Instantly share code, notes, and snippets.

@sarahhodne
Created July 7, 2010 20:15
Show Gist options
  • Save sarahhodne/467210 to your computer and use it in GitHub Desktop.
Save sarahhodne/467210 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
int main(int argc, char **argv)
{
char *command;
int i, size;
size = 0;
for (i=0; i<argc; i++) {
size += strlen(argv[i]) + 1; // The size of that string + 1 for the space
}
command = malloc((sizeof(char) * size) + 1); // Allocate the size of all the strings + spaces + the last null character
for (i=0; i<argc; i++) {
strcat(command, argv[i]); // Append the string
strcat(command, " "); // And a space
}
command[size] = '\0'; // Replace the last space with a null char to terminate the "string"
printf("%s\n", command);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment