/* mycp.cpp

   Makes a copy of an ascii file.
   This is a basic form of the cp command in linux.

   Usage: mycp <source file> <destination file>

   October 2009
*/
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <cstdio>
using namespace std;

int main(int argc, char *argv[])
{

  if(argc != 3){
	cout << "Missing or too many parameters." << endl;
	cout << "Usage: mycp <source file> <destination file>" << endl;
        return -1;
  }

  ifstream source( argv[1] );
  ofstream target( argv[2] );

  // Check if files can be opened
  if (source.is_open()==false){
    cout << "Unable to open file " << argv[1] << endl;
    return 1;
  }
  if (target.is_open()==false){
    cout << "Unable to open file " << argv[2] << endl;
    return 1;
  }

  char ch;

  source.get(ch);
  while( !(source.eof()) )
  {
    target << ch;
    source.get(ch);
  }
  source.close();
  target.close();

  cout << "File has been copied\n";

 return 0;
}