Skip to content

Instantly share code, notes, and snippets.

@gaviriar
Last active October 25, 2018 12:35
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 gaviriar/c7f96aed2b7ca9388f76dc44aa0388ed to your computer and use it in GitHub Desktop.
Save gaviriar/c7f96aed2b7ca9388f76dc44aa0388ed to your computer and use it in GitHub Desktop.
Parse arguments and concatenate to a sentence
/**
* @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