Listing 1

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

void myfunction1(char *format, ...)
   {
   va_list arg_ptr;
   va_start(arg_ptr,format);
   vfprintf(stdout,format,arg_ptr);
   va_end(arg_ptr);
   }

void myfunction2(char *format, ...)
   {
   FILE *fp;
   va_list arg_ptr;
   fp = fopen("TEST.DAT","a+");
   va_start(arg_ptr,format);
   vfprintf(fp,format,arg_ptr);
   va_end(arg_ptr);
   fclose(fp);
   }

void myfunction3(char *format, ...)
   {
   va_list arg_ptr1;
   va_list arg_ptr2;
   va_start(arg_ptr1,format);

   myfunction1(format,arg_ptr1);

   /* here I want to use the arguments of myfunction3(),
   va_end(arg_ptr1); but this code does not work */

   va_start(arg_ptr2,format);
   myfunction2(format,arg_ptr2);

   /* here I want to use the arguments of myfunction3(),
   va_end(arg_ptr2); but this code does not work */
   }

int main()
   {
   char msg[]="message";
   myfunction1("\n%s=%d=%f", msg, 2, 3.0); /* this works
fine */
   myfunction2("\n%s=%d=%f", msg, 2, 3.0); /* this works
fine */

   /* the following call of myfunction3() does not work.
   I want to have the same result, as
   if I call myfunction1() and myfunction2() isolated */

   myfunction3("\n%s=%d=%f", msg, 2, 3.0);
   }

/* End of File */