/* In its JUMPDISK appearance, this file is crunched. It is the source */
/* for a program that is presented in running form. To decrunch this */
/* file, see the Articles Menu item on DECRUNCHING. */
/* Before compiling, DELETE these first four lines of file. */

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

void main( int argc, char *argv[] );
long fsize( FILE *file );

long fsize( FILE *file )
{
   long filesize = 0;
   
   fseek( file, 0, 2 );                // position at end of file
   filesize = ftell( file );           // get file size
   fseek( file, 0, 0 );                // position at start of file
   return( filesize );
}

void main( int argc, char *argv[] )
{
   FILE *infile, *outfile;
   long count = 0, filesize = 0;
   int c = 0;
   
   if( argc != 4 )
   {
      printf( "Usage:  xjoin <input1> <input2> <output>\n" );
      exit( 0 );
   }
   
   infile = fopen( argv[1], "rb" );    // open the first input file
   if( infile == NULL )
   {
      printf( "Error!  Could not open file '%s'.\n", argv[1] );
      exit( 20 );
   }

   outfile = fopen( argv[3], "wb" );   // open the output file
   if( outfile == NULL )
   {
      printf( "Error!  Could not open file '%s'.\n", argv[2] );
      fclose( infile );
      exit( 20 );
   }
   
   filesize = fsize( infile );
   
   while( count < filesize )           // copy the first part
   {
      c = fgetc( infile );
      fputc( c, outfile );
      count++;
   }
   
   fclose( infile );                   // close the first input file
   
   infile = fopen( argv[2], "rb" );    // open the second input file
   if( infile == NULL )
   {
      printf( "Error!  Could not open file '%s'.\n", argv[1] );
      exit( 20 );
   }
   
   count = 0;
   filesize = fsize( infile );   
   while( count < filesize )           // copy the second part
   {
      c = fgetc( infile );
      fputc( c, outfile );
      count++;
   }
   
   fclose( infile );                   // close the first input file
   
   fclose( outfile );
   
   exit( 0 );
}
