Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>vfprintf() write formatted data to stream</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 vfprintf()              Write Formatted Data to Stream

 #include   <stdio.h>
 #include   <varargs.h>                 Use for UNIX V compatibility
 #include   <stdarg.h>                  Use for ANSI C standard compatibility

 int        vfprintf(stream,format-string,arg-ptr);
 FILE       *stream;                     Pointer to FILE structure
 const char *format-string;              Format control
 va_list    arg-ptr;                     Pointer to list of arguments

    vfprintf() formats and prints a series of characters and values to
    'stream'.  vfprintf() is similar to fprintf(), but instead of taking
    a list of arguments, it accepts a pointer to a list of arguments.

    'arg-ptr' has the type 'va_list'. 'va_list' is defined in <varargs.h>
    for UNIX V compatibility and in <stdarg.h> for compatibility with the
    proposed ANSI C standard.  'arg-ptr' points to a list of arguments.
    These arguments are converted and output according to specifications
    in 'format-string'.  (For the inner workings of variable-length
    parameter lists, see va_start(), va_arg(), and va_end()).

    See printf() for a complete description of 'format-string'.

   -------------------------------- Example ---------------------------------

    Using the UNIX V style, the following statements open a file, write
    data to it, and close it.

           #include <stdio.h>
           #include <varargs.h>

           FILE *stream;
           int x;
           main()
           {
               char *date = "12/21/86";
               char *header = "ANNUAL REPORT";

               if ((stream = fopen("TESTVA.DAT","w+")) != NULL) {
                   putdata("Data from : %s, (%s)\n",header,date);
                   for (x = 0; x < 100; x++)
                       putdata("%d",x);
                   putdata("\nEnd of Report\n");
                   fclose(stream);
               }
           }

           putdata(va_alist)
           {
               char *fmt_str;
               va_list arg_ptr;

               va_start(arg_ptr);
               fmt_str = va_arg(arg_ptr,char*);
               vfprintf(stream,fmt_str,arg_ptr);
               va_end(arg_ptr);
           }


See Also: printf() fprintf() va_arg()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson