Similar to Unix’s cp command. This program will be called with two parameters, the names of two files. It copies the second to the first.

[sourcecode language=’cpp’]

/*******************************************************
* MYCPLUS Sample Code – http://www.mycplus.com *
* *
* This code is made available as a service to our *
* visitors and is provided strictly for the *
* purpose of illustration. *
* *
* Please direct all inquiries to saqib at mycplus.com *
*******************************************************/

#include

int main(int argc, char * argv[]){
FILE *fin, *fout;
char c;

if (argc!=3){
printf(“Usage: %s fileout filein\n”, argc);
exit(0);
}
if ((fin=fopen(argv[2],”r”))==NULL){
perror(“fopen filein”);
exit(0);
}
if ((fout=fopen(argv[1],”w”))==NULL){
perror(“fopen fileout”);
exit(0);
}

while ((c=getc(fin))!=EOF)
putc(c,fout);

fclose(fin);
fclose(fout);
}[/sourcecode]

0 Shares
Share
+1
Tweet
Share
Stumble