我正在尝试将文件从指定库复制到当前目录。我可以完美地复制文本文件。任何其他文件都会损坏。程序在它应该检测到一个 feof 之前。
#include <stdio.h>
int BUFFER_SIZE = 1024;
FILE *source;
FILE *destination;
int n;
int count = 0;
int written = 0;
int main() {
unsigned char buffer[BUFFER_SIZE];
source = fopen("./library/rfc1350.txt", "r");
if (source) {
destination = fopen("rfc1350.txt", "w");
while (!feof(source)) {
n = fread(buffer, 1, BUFFER_SIZE, source);
count += n;
printf("n = %d\n", n);
fwrite(buffer, 1, n, destination);
}
printf("%d bytes read from library.\n", count);
} else {
printf("fail\n");
}
fclose(source);
fclose(destination);
return 0;
}