我想將文件從指定的庫複製到當前目錄。我可以完美地複製文本文件。任何其他文件都會損壞。程序在它應該之前檢測到一個feof。如何讀取c中的二進制文件? (視頻,圖像或文本)
#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;
}
修正了它。謝謝。 –