I take it by optional parameters you mean the same effect as printf? You can make use of the macros defined in stdarg.h.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
void va_Error ( const char *fmt, va_list args )
{
vfprintf ( stderr, fmt, args );
}
void Error ( const char *fmt, ... )
{
va_list args;
va_start ( args, fmt );
va_Error ( fmt, args );
va_end ( args );
exit ( EXIT_FAILURE );
}
int main ( void )
{
Error ( "Fatal error %d : %s\n", 1, "Stupid user" );
return EXIT_SUCCESS;
}
-Prelude