In any case, given two file names, the procedure in C is simple.
fopen(filename1, "rb"), fopen(filename2, "wb"), fread() from file 1 and
fwrite() to file 2 until you run out of data, fclose() both files.
That's it.
A production quality copy function in C is not trivial. The code you
can find on the internet is mostly defective. A production quality
copy function at least needs:
- an explicit policy wrt overwriting an existing file
- preparation for the worse cases, ie. return values of read, write,
and close functions and/or stream state must be checked
- preparation for the worst case, the crash during copying
The last requirement implies that the file is first written to a
temporary file (in the same directory as the destination file) and
renamed later after all copying is reliably finished. A production
quality copy function would probably use the Posix I/O functions
instead of stdio because they provide some essential features not
present in stdio, e.g. you can open a file with O_CREAT | O_EXCL or
flush data to disk with fsync (_commit on Windows).