块读写的文件复制
#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 1000
void copyFileBuf(char *source, char *dest);
int main()
{
char source[80] = "D:\\CodeLibrary\\文件读写\\Data\\dict.dic",
dest[80] = "D:\\CodeLibrary\\文件读写\\Data\\test.dat";
copyFileBuf(source, dest);
return 0;
}
void copyFileBuf(char *source, char *dest)
{
char buffer[BUFSIZE];
FILE *in, *out;
if ((in = fopen(source, "rb")) == NULL)
{
fprintf(stderr, "can't open the file \"%s\"\n", source);
exit(1);
}
if ((out = fopen(dest, "wb")) == NULL)
{
fprintf(stderr, "can't created the file \"%s\"\n", dest);
exit(2);
}
printf("\nCopying text file %s to file %s by Block. \n", source, dest);
int readCount;
while ((readCount = fread(buffer, 1, BUFSIZE, in)) > 0)
fwrite(buffer, readCount, 1, out);
if (fclose(in) != 0 || fclose(out) != 0)
fprintf(stderr, "Error in closing files\n");
}