While I agree with the general spirit of your post, please allow me to introduce you to a magic function called 'asprintf'!
'man 3 asprintf' says:
"The functions asprintf() and vasprintf() are analogs of sprintf(3) and vsprintf(3), except that they allocate a string large enough to hold the
output including the terminating null byte, and return a pointer to it via the first parameter. This pointer should be passed to free(3) to
release the allocated storage when it is no longer needed."
So your very long example just became a bit shorter. Of course you need to check if the returned string != NULL (just in case there wasn't enough memory). You also gain all the nice formatting functions of printf (though "%s%s" will do nicely in your example).
All power corrupts, but we need electricity.