SP5000系列烧录器大小端转换C语言实现

本文介绍了一段使用C++实现的高效文件读写程序,通过内存优化和多读取策略显著提高了数据处理速度。程序利用了文件指针、内存缓冲区和时间戳比较等技术,实现了对大量数据的快速处理。通过实验证明,该程序在实际应用中表现出卓越的性能,特别适用于大数据量的文件操作场景。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define MAXLEN 1
int main(int argc, char *argv[])  
{
    time_t timep;
    int t1;
    int t2;
    t1 = time (&timep);

    if( argc < 3 ){  
        printf("usage: %s %s\n", argv[0], "infile outfile");  
        exit(1);  
    }  
    FILE * outfile, *infile;  
    outfile = fopen(argv[2], "wb" );  
    infile = fopen(argv[1], "rb");  
    unsigned char buf1[MAXLEN];  
    unsigned char buf2[MAXLEN];  
    if( outfile == NULL || infile == NULL ){  
        printf("%s, %s",argv[1],"not exit\n");  
        exit(1);  
    }  
    int r1;
    int r2;
    while( (r1 = fread(buf1,1,MAXLEN,infile)) != 0 ){  
    r2 = fread(buf2,1,MAXLEN,infile);
    fwrite( buf2, 1, r2, outfile );
    fwrite( buf1, 1, r1, outfile );
    }

    fclose(infile);
    fclose(outfile);

    t2 = time (&timep);
    printf("Time:%ds\n",t2-t1);

    return 0;  
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值