Last active
October 25, 2018 12:35
-
-
Save gaviriar/c7f96aed2b7ca9388f76dc44aa0388ed to your computer and use it in GitHub Desktop.
Parse arguments and concatenate to a sentence
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
/** | |
* @brief Concatenate the strings in input | |
* arguments to a space separated sentence | |
* into an output buffer. | |
*/ | |
void parse_args(int argc, char* argv[], char* buffer) | |
{ | |
// copy the first argument | |
strcpy(buffer, argv[1]); | |
// contatenate each proceeding argument | |
// with a space beforehand | |
for (int i = 2; i < argc; ++i) { | |
strcat(buffer, " "); | |
strcat(buffer, argv[i]); | |
} | |
// Null terminate the buffer | |
strcat(buffer, "\0"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment