#include <stdio.h>
int main(int argc, const char *argv[])
{
//1文件拷贝到2文件
FILE* fileA=fopen(argv[1],"r");
FILE* fileB=fopen(argv[2],"w+");
if(NULL==fileA){
perror("fopen");
return -1;
}
if(NULL==fileB){
perror("fopen");
return -1;
}
char c;
puts("------开始拷贝fileA------");
while((c=fgetc(fileA))!=EOF){
putchar(c);
fputc(c,fileB);
}
fclose(fileA);
fclose(fileB);
FILE* fileC=fopen(argv[2],"r");
puts("\n------拷贝结束------");
while((c=fgetc(fileC))!=EOF){
putchar(c);
}
fclose(fileC);
return 0;
}
#include <stdio.h>
int main(int argc,const char* argv[]){
//fscanf/fprintf
FILE* fileC=fopen(argv[1],"r");
FILE* fileD=fopen(argv[2],"w+");
if(NULL==fileC){
perror("fopen");
return -1;
}
if(NULL==fileD){
perror("fopen");
return -1;
}
char c;
puts("------开始拷贝fileC------");
while(fscanf(fileC,"%c",&c)!=EOF){
printf("%c",c);
fprintf(fileD,"%c",c);
}
fclose(fileC);
puts("\n------拷贝结束------");
fseek(fileD,0,SEEK_SET);
while(fscanf(fileD,"%c",&c)!=EOF){
printf("%c",c);
}
fclose(fileD);
}
#include <stdio.h>
int main(int argc, const char *argv[])
{
//fgets fputs
FILE* fileA=fopen(argv[1],"r");
FILE* fileB=fopen(argv[2],"w+");
if(NULL==fileA){
perror("fopen");
return -1;
}
if(NULL==fileB){
perror("fopen");
return -1;
}
char c[10];
while(fgets(c,sizeof(c),fileA)!=NULL){
fputs(c,fileB);
}
fclose(fileA);
fclose(fileB);
return 0;
}