Woo hoo, thanks for the tip!
But I still need to worry about creating a memory leak with this. :(
Also, asprintf is a GNU-extension, so if you want to write portable code, it's a no-go (as for everything usefull in C).
Thankfully, I'm not doing much C any more. Those hoity-toity hand-holding languages have spoiled me, and now I don't want to be bothered about memory management and other "trivia." :)
Not exactly the same thing, but routine string manipulation in C gets considerably easier once you discover a highly underrated function called asprintf (basically combines sprintf and malloc, calculating the buffer size for you).