/* * Program to copy file. Input and output filenames are given * as command-line arguments. */ #include #include int main(int argc, char* argv[]) { if (argc != 3) { fprintf(stderr, "usage: %s infile outfile\n", argv[0]); return EXIT_FAILURE; } FILE * infile = fopen(argv[1], "r"); if (infile == NULL) { fprintf(stderr, "cannot open file %s\n", argv[1]); return EXIT_FAILURE; } FILE * outfile = fopen(argv[2], "w"); if (outfile == NULL) { fprintf(stderr, "cannot open file %s\n", argv[2]); return EXIT_FAILURE; } int inchar; while ((inchar = fgetc(infile)) != EOF) { fputc(inchar, outfile); } fclose(infile); fclose(outfile); return EXIT_SUCCESS; }