long copyFile(const char* src, const char* dest)
{
long count = 0L;
FILE* fileIn;
FILE* fileOut;
int readLen;
int buffer_len = 512;
unsigned char buffer[buffer_len];
size_t size = sizeof(unsigned char);
if(!(fileIn = fopen(src, "rb")) )
{
printf("open %s file fail.\n", src);
return -1;
}
if(!(fileOut = fopen(dest, "wb+")) )
{
printf("create/open %s file fail.\n", dest);
return -1;
}
while(0 < (readLen = fread(buffer, size, buffer_len, fileIn) ) )
{
count+=readLen;
fwrite(buffer, size, readLen, fileOut);
}
fclose(fileIn);
fclose(fileOut);
return count;
}
#include <stdio.h>
#include <stdlib.h>