/* vfprintf example */
#include <stdio.h>
#include <stdarg.h>
void WriteFormatted (FILE * stream, const char * format, ...)
{
va_list args;
va_start (args, format);
vfprintf (stream, format, args);
va_end (args);
}
int main ()
{
FILE * pFile;
pFile = fopen ("myfile.txt","w");
WriteFormatted (pFile,"Call with %d variable argument.\n",1);
WriteFormatted (pFile,"Call with %d variable %s.\n",2,"arguments");
fclose (pFile);
return 0;
}
|
Call with 1 variable argument. Call with 2 variable arguments. |
| vprintf | 将格式化的数据从变量参数列表打印到标准输出(function ) |
| printf | 将格式化的数据写入stdout(function ) |
| vsprintf | 将格式化的数据从变量参数列表写入字符串(function ) |
| fprintf | 将格式化的数据写入流(function ) |