Created
July 7, 2010 20:15
-
-
Save sarahhodne/467210 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <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