#include <stdio.h>
int main(void){
char file1[10],file2[10],ch,*p;
FILE *fp1,*fp2,*temp;
/*
printf("file1:\n");
gets(file1);
printf("file2:\n");
gets(file2);
*/
printf("enter 2 files to switch the contents:\n");
scanf("%s %s",file1,file2);
fp1=fopen(file1,"rb");
temp=fopen("temp.txt","w+b");
for(;;)
{
ch=fgetc(fp1);
if(ch==EOF) break;
fputc(ch,temp);
}
fclose(fp1);
fclose(temp);
fp2=fopen(file2,"rb");
fp1=fopen(file1,"wb");
for(;;)
{
ch=fgetc(fp2);
if(ch==EOF) break;
fputc(ch,fp1);
}
fclose(fp1);
fclose(fp2);
temp=fopen("temp.txt","rb");
fp2=fopen(file2,"wb");
for(;;)
{
ch=fgetc(temp);
if(ch==EOF) break;
fputc(ch,fp2);
}
fclose(fp2);
fclose(temp);
return 0;
} |