bigfile.c #include <stdio.h> int main(int argc,char argv[]) { FILE *fp1,*fp2; char buf[1024]; int nbytes; if(argc!=3) { printf("wrong command/n"); exit(1); } if((fp1=fopen(argv[1],"rd"))==NULL) { perror("fail to open"); exit(2); } if((fp2=fopen(argv[2],"rd"))==NULL) { perror("fail to open"); exit(3); } //开始复制文件,文件可能很大,缓冲区一次装不下,所以使用一个循环进行读写 while((n=fread(buf,sizeof(char),1024,fp1))>0) { buf[n]='/0'; if(fwrite(buf,sizeof(char),n,fp2))==-1) { perror("fail to write"); exit(4); } } if(n==1) { perror("fail to read"); exit(5); } fclose(fp1); fclose(fp2); } test: #gcc -o bigfile bigfile.c #./bigfile testsrc.txt testdes.txtbigfile.c #include <stdio.h> int main(int arg 你的当前访问异常,请进行认证后继续阅读剩余内容。 提交