#include <stdio.h>
#include <stdlib.h>

void append_file (char *file_in, char *file_out)
{
 FILE *f1, *f2;
 int r;
 char *buffer;

 if (file_in == NULL) exit (3);
 if (file_out == NULL) exit (3);

 printf ("Appending files: %s %s\n", file_in, file_out);

 f1 = fopen (file_in, "ab");
 if (f1 == NULL)
  {
   exit (1);
  }
 f2 = fopen (file_out, "rb");
 if (f2 == NULL)
  {
   fclose (f1);
   exit (2);
  }

 buffer = malloc (50 * 1024);
 if (buffer == NULL) exit (4);

 while (! feof (f2))
  {
   if ((r = fread (buffer, 1, 50 * 1024 - 1, f2)) > 0)
    fwrite (buffer, 1, r, f1);
   printf (".");
  }
 fclose (f1);
 fclose (f2);
 free (buffer);
 printf ("\n");
}


/*******************************************/


int main (int argc, char *argv[])
{
 int i;

 if (argc < 3)
  {
   printf ("Usage: appendfile.exe file1 file2 ... file99\n");
   exit (-1);
  }

 for (i = 2; i < argc; i++)
  {
   append_file (argv[1], argv[i]);
  }
 return (0);
}



