/* * Actually copy one file into another. */ #include #include long fileCopy(const char *dest, const char *source) { FILE *sfp; /* source file pointer */ FILE *dfp; /* destination file pointer */ int c; /* next input character */ long cnt = -1L; /* count of characters copied */ if ((sfp = fopen(source,"rb")) == NULL) printf("Can't open %s for reading\n", source); else { if ((dfp = fopen(dest,"wb")) == NULL) printf("Can't open %s for writing\n", dest); else { for (cnt = 0L; (c = getc(sfp)) != EOF; cnt++) putc(c,dfp); fclose(dfp); } fclose(sfp); } return cnt; }