#include #include #include #include char *fmtmsg( char *format, ... ) { char *msgbuf; int len; va_list arglist; va_start( arglist, format ); len = vsnprintf( NULL, 0, format, arglist ); va_end( arglist ); len = len + 1 + 7; msgbuf = malloc( len ); strcpy( msgbuf, "Error: " ); va_start( arglist, format ); vsnprintf( &msgbuf[7], len, format, arglist ); va_end( arglist ); return( msgbuf ); } void main() { char *msg; msg = fmtmsg( "%s %d %s", "Failed", 100, "times" ); printf( "%s\n", msg ); free( msg ); }