I want to be able to create a template string and then use it like this:
int execute_command(char *cmd) {
//...
}
char *template_command = "some_command %s some_args %s %d";
char *actual_command = template_command % (cmd1, arg1, 123);
// error, how do I do that?
int res = execute_command(actual_command);
snprintf
, and remember to allocate enough space. Usemalloc
for that. POSIXasnprintf
does that all for you, easy to define it yourself.