Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How can I write a function that takes a format string and a variable number of arguments
How can I write a function that takes a format string and a variable number of arguments, like printf, and passes them to printf to do most of the work?
✍: Guest
Use vprintf, vfprintf, or vsprintf. These routines are like their counterparts printf, fprintf, and sprintf, except that instead of a variable-length argument list, they accept a single va_list pointer.
As an example, here is an error function which prints an error message, preceded by the string ``error: '' and terminated with a newline:
#include <stdio.h>
#include <stdarg.h>
void error(const char *fmt, ...)
{
va_list argp;
fprintf(stderr, "error: ");
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
fprintf(stderr, "\n");
}
2015-06-12, 1137👍, 0💬
Popular Posts:
How Are Vertical Margins between Two Block Elements Collapsed? - CSS Tutorials - Understanding Multi...
How To Create Nested Tables? - XHTML 1.0 Tutorials - Understanding Tables and Table Cells You can cr...
Why is there extra white space before or after tables? This is often caused by invalid HTML syntax. ...
How To Select an Oracle System ID (SID)? - Oracle DBA FAQ - Creating New Database Instance Manually ...
Describe different elements in Static Chart diagrams ? Package: - It logically groups element of a U...