call printf using va_list
Instead of printf
, I recommend you try vprintf
instead, which was created for this specific purpose:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
void errmsg( const char* format, ... )
{
va_list arglist;
printf( "Error: " );
va_start( arglist, format );
vprintf( format, arglist );
va_end( arglist );
}
int main( void )
{
errmsg( "%s %d %s", "Failed", 100, "times" );
return EXIT_SUCCESS;
}
Source
Use vprintf()
instead.