User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdio.h:vfprintf

vfprintf

int vfprintf(FILE *stream, const char *format, va_list arg);

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

/* 
 * 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;
}

output

test.txt
Hello World
vfprintf test line

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/vfprintf.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz