Copying Files with C library

Hi all,

Is there a function that can copy the contents pointed to by one FILE* to another? If not, how would you suggest I implement this? I'm using the C file I/O mostly to experiment, and I'm wondering if this is doable.


That link contains an example on putc which can be adapted. The example shows the use of stdio.h but if this is c++ you should just go ahead and use #include <cstdio> instead. It is a very simple adaptation where you use getc to get the data from the input file and putc to write it to the other. You simply loop until the entire file is processed. You open the output file using the "w" flag so that it will simply overwrite or "a" if you want to append to an existing file. Follow the links to see what other flags are used to open files.

This contains a link to other functions in that library.
Topic archived. No new replies allowed.