#include #include #define BUFFER_SIZE 1024 size_t copyFile( FILE *, FILE * ); int main( int argc, char *argv[] ) { FILE *small, *big, *out; size_t curByte; small = fopen( argv[ 1 ], "r" ); big = fopen( argv[ 2 ], "r" ); out = fopen( argv[ 3 ], "w" ); assert( NULL != small && NULL != big && NULL != out ); curByte = copyFile( small, out ); fseek( big, curByte, SEEK_SET ); copyFile( big, out ); fclose( small ); fclose( big ); fclose( out ); return 0; } size_t copyFile( FILE *in, FILE *out ) { size_t readBytes, writtenBytes, curByte; char buffer[ BUFFER_SIZE ]; curByte = 0; while( ! feof( in ) ) { readBytes = fread( buffer, sizeof( char ), BUFFER_SIZE, in ); writtenBytes = fwrite( buffer, sizeof( char ), readBytes, out ); assert( readBytes == writtenBytes ); curByte += readBytes; } return curByte; }