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, 1339👍, 0💬
Popular Posts:
Which bit wise operator is suitable for turning on a particular bit in a number? The bitwise OR oper...
What is the purpose of Replication ? Replication is way of keeping data synchronized in multiple dat...
What are different properties provided by Objectoriented systems ? Following are characteristic’s of...
What is the difference between include directive & jsp:include action? Difference between includ...
How To Create an Array in PL/SQL? - Oracle DBA FAQ - Introduction to PL/SQL If you want create an ar...