by thinkpad20 · 12y ago · 0 comments
struct string {
char *str;
unsigned length;
} "%.*s"
or possibly even "%*.*s"
if you want it space padded. In principle you can bound your space usage and avoid an snprintf with such constructs; in practice, it's probably better to still use snprintf (if you're using standard-library string functions at all).