You could try something like below:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char**argv)
{
char mybuf[BUFSIZ];
FILE *infd;
FILE *outfd;
if (!(infd = fopen("infile", "r")))
{
fputs("could not open infile!\n", stderr);
exit(EXIT_FAILURE);
}
if (!(outfd = fopen("outfile", "w")))
{
fputs("could not open outfile!\n", stderr);
exit(EXIT_FAILURE);
}
while ((fwrite(mybuf, 1, fread(mybuf, 1, BUFSIZ, infd), outfd))){}
fclose(outfd);
fclose(infd);
exit(EXIT_SUCCESS);
}