#include int main (int argc, char * argv []) { if (argc != 3) { printf("usage: %s \n", argv[0]); return 1; } FILE * src = fopen(argv[1], "r"); if (src == 0) { printf("could not open source file %s\n", argv[1]); return 1; } FILE * dst = fopen(argv[2], "w"); if (dst == 0) { printf("could not open destination file %s\n", argv[2]); fclose(src); return 1; } static const unsigned int BLOCK_SIZE = 1024; char buffer[BLOCK_SIZE]; size_t res; while ((res = fread(buffer, 1, BLOCK_SIZE, src)) > 0) { do { char * buf_w_pos = buffer; size_t w_res = fwrite(buf_w_pos, 1, res, dst); if (w_res == 0) { printf("could write onto destination file %s\n", argv[2]); fclose(src); fclose(dst); return 1; } buf_w_pos += w_res; res -= w_res; } while (res > 0); } fclose(src); fclose(dst); }