// crt_vsprintf_s.c // This program uses vsprintf_s to write to a buffer. // The size of the buffer is determined by _vscprintf. #include <stdlib.h> #include <stdarg.h> void test( char * format, ... ) { va_list args; int len; char * buffer; va_start( args, format ); len = _vscprintf( format, args ) // _vscprintf doesn't count + 1; // terminating '/0' buffer = malloc( len * sizeof(char) ); vsprintf_s( buffer, len, format, args ); puts( buffer ); free( buffer ); } int main( void ) { test( "%d %c %d", 123, '<', 456 ); test( "%s", "This is a string" ); } Output 123 < 456 This is a string