Your implementation could be a simple loop like this, which repeats until there were no bytes read. Note that sizeof(char*)
is wrong - the size of a pointer, and that sizeof(char)
is 1
by definition.
#include <stdio.h> // include proper header
#define BUFFSIZE 512 // power of 2 is kind to system
int main(void)
{
char buffer[BUFFSIZE];
size_t bytes;
FILE *fin, *fou;
fin = fopen("CSV.csv", "rb");
fou = fopen("CSVDest.csv", "wb");
if(fin == NULL || fou == NULL)
return 1; // or other action
while ((bytes = fread(buffer, 1, BUFFSIZE, fin)) != 0) {
if(fwrite(buffer, 1, bytes, fou) != bytes) {
return 1; // or other action
}
}
fclose(fou);
fclose(fin);
return 0;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…