/* va_start example */
#include <stdio.h> /* printf */
#include <stdarg.h> /* va_list, va_start, va_arg, va_end */
#include <string.h> /* strdup - duplicate a string */
#include <stdlib.h> /* exit(0) */
#define HTMLFILE_DEF "./ipband.html"
char *htmlfname_m; /* HTML report output file */
/* HTML reports */
void html_report(char *cp,...) {
va_list va;
static FILE *htmlfile; /* static to persist across calls */
if (!cp) { /* Cleanup when called with NULL format string */
if (htmlfile) {
if (htmlfile != stdout) {
fclose(htmlfile);
}
htmlfile = NULL;
}
} else { /* Get handles and print */
if (!htmlfile) {
if (! htmlfname_m) {
htmlfname_m = strdup(HTMLFILE_DEF);
}
if (strcmp("-",htmlfname_m)) {
htmlfile = fopen (htmlfname_m, "w");
} else {
htmlfile = stdout;
}
if (NULL==htmlfile) {
fprintf(stderr,"ERROR: Cannot open output file <%s>\n", htmlfname_m);
exit(0);
}
}
va_start(va,cp);
if (htmlfile) {
vfprintf(htmlfile,cp,va);
}
va_end(va);
}
}
int main ()
{
html_report("<html>\n");
return 0;
}
Report:
Produce ipband.html
Reference:
1.enter link description here
0 意見:
張貼留言