1. 程式人生 > >C語言複製二進位制檔案

C語言複製二進位制檔案

#include <stdio.h>
#include<stdlib.h>
#define APACITY 2048
int main(){
    FILE * input= fopen("D:\\movie.mkv","rb");
    FILE * output= fopen("D:\\電影.mkv","wb");

    if(input==NULL){
        printf("檔案無法開啟");
        exit(0);
    }

    if(output==NULL){
        printf("檔案無法開啟");
        exit(0);
    }

    int buffer [APACITY];//或int * buffer = malloc(APACITY);
    int validCount = 0;//實際存入多少個數據項
    while((validCount=fread(buffer,sizeof(int),APACITY,input))!=0){
        fwrite(buffer,sizeof(int),validCount,output);
    }

    fclose(input);
    fclose(output);
    printf("檔案複製完成");
    return 0;
}