// file: bcp.C // author: Brian Buhman // date: 17 March 1997 // // This program copies the file specified in the first of the // command line argument to the file specified by the second command // line argument. The idea is to illustrate some simple file I/O. // Just for fun, I'll make all of the destination file's output // uppercase. Beware!! The program will overwrite the file listed // as the second argument #include #include #include #include // argc number of arguments on the command line, including the exe name. // argv array of the argument character strings. int main( int argc, char * argv[] ) { if ( argc != 3 ) { cerr << "usage: bcp infile outfile\n"; exit( -99 ); } // open the first arg as the input file. ifstream infile( argv[1], ios::in ); if ( !infile ) { cerr << argv[1] << " could not be opened for reading\n"; exit( -1 ); } // open the second arg as the output file. ofstream outfile( argv[2], ios::out ); if ( !outfile ) { cerr << argv[2] << " could not be opened for writing\n"; exit( -1 ); } char ch; // Keep reading chars until the end of the file is reached. while ( infile.get( ch ) ) { if ( isalpha( ch ) ) outfile << (char) toupper( ch ); else outfile << ch; } // close the files! infile.close(); outfile.close(); return( 0 ); }