/* vsprintf example */ #include <stdio.h> #include <stdarg.h> void PrintFError ( const char * format, ... ) { char buffer[256]; va_list args; va_start (args, format); vsprintf (buffer,format, args); perror (buffer); va_end (args); } int main () { FILE * pFile; char szFileName[]="myfile.txt"; pFile = fopen (szFileName,"r"); if (pFile == NULL) PrintFError ("Error opening '%s'",szFileName); else { // file successfully open fclose (pFile); } return 0; } |
Error opening file 'myfile.txt': No such file or directory |
vfprintf | 将格式化的数据从变量参数列表写入流(function ) |
printf | 将格式化的数据写入stdout(function ) |
sprintf | 将格式化的数据写入字符串(function ) |
vprintf | 将格式化的数据打印到标准输出(function ) |