This is a simple C program that copies the contents of one ASCII (text) file onto another file. It is similar to Unix’s cp command.
Unleash your gaming potential with the Logitech G502 Hero Gaming Mouse – precision, customizability, and comfort for the ultimate competitive edge!
View on Amazon
This C program is called with two parameters i.e. the names of two files (fin and fout). The contents of the file referenced in second parameter are copied onto the file which is referenced by first parameter.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <stdio.h> 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); } |