With clib:
clib install aperezdc/dbuf
#include "dbuf.h"
int
main(int argc, char **argv)
{
struct dbuf b = DBUF_INIT;
dbuf_addstr(&b, "Command line arguments:\n");
for (int i = 1; i < argc; i++) {
dbuf_addstr(&b, argv[i]);
dbuf_addch(&b, '\n');
}
puts(buf_str(&b));
dbuf_clear(&b);
return EXIT_SUCCESS;
}