/ Published in: C
With the code fragment below, you can easily add output logging to a text-based program. Add the functions, open the log file and replace calls to (f)printf by (f)printflog.
Expand |
Embed | Plain Text
FILE *log= NULL; int printflog( const char *format, ... ) { va_list arglist; int ret; va_start(arglist, format); ret= vprintf(format, arglist); if( log ) vfprintf(log, format, arglist); return ret; } int fprintflog( FILE *stream, const char *format, ... ) { va_list arglist; int ret; va_start(arglist, format); ret= vfprintf(stream, format, arglist); if( log ) vfprintf(log, format, arglist); return ret; }
You need to login to post a comment.
