#include"stdio.h"
#include"stdlib.h"
void writefile(FILE*fp)
{
char ch;
int n;
printf("输入内容以#结束:");
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);
ch=getchar();
}
rewind(fp);
}
int main()
{
FILE*fp,*in,*out;
char ch,c,infile[30],outfile[30],inputfile[30];
int key;
printf("输入密码:");
scanf("%d",&key);
printf("要打开的文件:");
scanf("%s",inputfile);
fp=fopen(inputfile,"wt+");
if(fp==NULL)
{
printf("Eof");
exit(0);
}
else
printf("%s打开",inputfile);
writefile(fp);
printf("输入要保存的文件名:");
scanf("%s",infile);
if((in=fopen(infile,"w"))==NULL)
{
printf("文件保存成功");
exit(0);
}
ch=fgetc(fp);
while(ch!=EOF)
{
c=ch^key;
fputc(c,in);
ch=fgetc(fp);
}
fclose(fp);
fclose(in);
//readfile(fp,key);
}