/* * Program to copy characters from file supplied as command-line argument * to file supplied as command-line argument. */ #include int main(int argc, char *argv[]) { int inchar; FILE *infile; FILE *outfile; if (argc < 3) { fprintf(stderr, "usage: %s infile outfile\n", argv[0]); return 1; } infile = fopen(argv[1], "rb"); if (infile == NULL) { fprintf(stderr, "unable to open input file %s\n", argv[1]); return 1; } outfile = fopen(argv[2], "wb"); if (outfile == NULL) { fprintf(stderr, "unable to open output file %s\n", argv[2]); return 1; } while ( (inchar = fgetc(infile)) != EOF ) { fputc(inchar, outfile); } fclose(infile); fclose(outfile); return 0; }