文本文件加密,C语言写的!望大家多提意见。
#include<stdio.h>#include<stdlib.h>
int main()
{
FILE *fp,*temp;
int i=0,a=0;
char ch,strfilename[30],strtempbuff[256],pass;
printf("请输入要加密的文件:\n");
gets(strfilename);
if((fp=fopen(strfilename,"rb+"))==NULL)
{
printf("文件%s不存在!\n",strfilename);
return -1;
}
if((temp=fopen("tempfile.txt","wb+"))==NULL)
{
printf("临时文件创建失败!\n");
return -1;
}
while(fread(&pass,sizeof(char),1,fp))
i++;
pass='\0';
rewind(fp);
while(a<i)
{
ch=fgetc(fp);
ch=~ch;
fputc(ch,temp);
a++;
}
fclose(temp);
fclose(fp);0
sprintf(strtempbuff,"del %s",strfilename);
system(strtempbuff);
sprintf(strtempbuff,"ren tempfile.txt %s",strfilename);
system(strtempbuff);
printf("加密成功!\n");
system("pause");
return 0;
}