I have to write a program that emulates the Unix cat command. The program accepts between 2 to 9 files from dos command line.
eg concat file 1 file 2 file3 ...... // concat being the name of my program....files 2 and 3 will be copied to file 1 in that order..... I have written a program that allows for 3 arguments.... copying the second into the first...how would i go about changing it to allow for multiply files..........this is the code I have
Code:
#include <fstream.h> //for I/O files
#include <iostream.h>
using namespace std;
#include <process.h> //for exit
int main(int argc, char* argv[])
{
if(argc != 3)
{
cerr << "\nFormat: ocopy srcfile destfile";
exit(-1);
}
char ch;
ifstream infile; //create input file
infile.open(argv[1]); //open file
if(!infile)
{cerr << "\nCan't open " << argv[1]; exit(-1);}
ofstream outfile; //create output file
outfile.open(argv[2]); //open output file
if(!outfile)
{cerr << "\nCan't open " << argv[2]; exit(-1);}
while(infile) //until EOF
{
infile.get(ch); //read a character
outfile.put(ch); //write a character
}
return 0;
}
any help would be great.....thanks