This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/vsnprntf.c

34 lines
639 B
C

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
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 );
}