This shows you the differences between two versions of the page.
— |
c:stdio.h:vfprintf [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | {{keywords>wiki library source code example reference}} | ||
+ | ====== vfprintf ====== | ||
+ | |||
+ | <code c> | ||
+ | int vfprintf(FILE *stream, const char *format, va_list arg); | ||
+ | </code> | ||
+ | Equivalent to fprintf with variable argument list replaced by arg, which must have been initialised by the va_start macro (and may have been used in calls to va_arg). | ||
+ | |||
+ | ===== C Sourcecode Example ===== | ||
+ | <code c> | ||
+ | /* | ||
+ | * vfprintf example code | ||
+ | * http://code-reference.com/c/stdio.h/vfprintf | ||
+ | */ | ||
+ | |||
+ | #include <stdio.h> /* including standard library */ | ||
+ | //#include <windows.h> /* uncomment this for Windows */ | ||
+ | |||
+ | #include <stdarg.h> | ||
+ | |||
+ | int myfprintf( FILE *file, char const * format, ... ) | ||
+ | { | ||
+ | va_list args; | ||
+ | int n; | ||
+ | |||
+ | va_start( args, format ); | ||
+ | n=vfprintf( file, format, args ); | ||
+ | va_end( args ); | ||
+ | fputs("vfprintf test line\n", file); | ||
+ | |||
+ | return n; | ||
+ | } | ||
+ | |||
+ | int main (void) | ||
+ | { | ||
+ | char string[] ="Hello"; | ||
+ | FILE * stream = fopen("test.txt","w"); | ||
+ | if(stream == 0) { | ||
+ | perror("file problem"); | ||
+ | } | ||
+ | |||
+ | myfprintf( stream, " %s World\n", string); | ||
+ | |||
+ | fclose(stream); | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ==== output ==== | ||
+ | |||
+ | == test.txt == | ||
+ | <code c> | ||
+ | Hello World | ||
+ | vfprintf test line | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||