C语言中二进制读写文件函数fread和fwrite

fopen,fread,fwrite:二进制读写的顺序是用fopen以二进制方式打开读写文件,然后使用fread和fwrite两个函数将数据写入二进制文件中

#include 
#include 
#define MAXLEN 1024

int main(int argc, char *argv[])

{
    FILE * outfile, *infile;

    outfile = fopen(argv[2], "wb" );

    infile = fopen(argv[1], "rb");

    unsigned char buf[MAXLEN];

    if( outfile == NULL || infile == NULL )

    {

        printf("%s, %s",argv[1],"not exit/n");

        exit(1);

    }   

   

    int rc;

    while( (rc = fread(buf,sizeof(unsigned char), MAXLEN,infile)) != 0 )

    {

        fwrite( buf, sizeof( unsigned char ), rc, outfile );

} 

fclose(infile);

fclose(outfile);

 system("PAUSE"); 

 return 0;

}

你可能感兴趣的:(C++)