发布时间:2019-07-31 16:32:24
#define MAXLEN 1024 int main(int argc, char *argv[]) { 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 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; } 1 小时前 浏览 31 次 贪污韩文歌 分享 修改问题 提高悬赏15 收到答案发送短信通知到180******50 1个回答 fastfs 52 分钟前 #define MAXLEN 1024 int main(int argc, char *argv[]) { if( argc < 3 )//输入参数小于2 { 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 buf[MAXLEN]; //其中一个打开失败 if( outfile == NULL || infile == NULL ) { printf("%s, %s",argv[1],"not exit/n"); exit(1); } int rc; //读入1字节 while( (rc = fread(buf,sizeof(unsigned char), MAXLEN,infile)) != 0 ) { //写入1字节 fwrite( buf, sizeof( unsigned char ), rc, outfile ); } fclose(infile); fclose(outfile); system("PAUSE"); return 0; }
如果我想打开一个二进制文件并修改里面的内容(比如说加一段)应该怎么修改这个程序,第一次做这个东西