|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
/******************文件操作函数库*************************
设计: ahu
主页: web.1816.net/~program
*********************************************************/
#include <stdio.h>
#include <dos.h>
int file_copy(char*old_fname,char*new_fname); /*文件拷贝*/
int file_kill(char *filename); /*文件删除*/
int file_password(char*old_file_name,char*new_file_mame,long password);
/*文件加密(password为密码),加解密采用相同的密锁*/
int file_copy(char*old_fname,char*new_fname)
{
FILE*in,*out;
char ch;
if ((in=fopen(old_fname,"r"))==NULL) return(1);
if ((out=fopen(new_fname,"w"))==NULL) { fclose(out); return(2);}
ch=fgetc(in);
while (!feof(in))
{
fputc(ch,out);
ch=fgetc(in);
}
fclose(in);
fclose(out);
return(0);
}
int file_kill(char *filename)
{
FILE *fp;
fp=fopen(filename,"w");
if(fp==NULL) return(1);
fclose(fp);
unlink(filename);
return(0);
}
int file_password(char *old_file_name,char*new_file_mame,long password)
{
FILE *fp1,*fp2;
char c,ch;
fp1=fopen(old_file_name,"rb");
fp2=fopen(new_file_mame,"wb");
if(fp1==NULL) return(1);
if(fp2==NULL) { fclose(fp1); return(2); }
srand(password);
ch=fgetc(fp1);
while(! feof(fp1))
{
c=rand();
ch=ch^c;
fputc(ch,fp2);
ch=fgetc(fp1);
}
fclose(fp1);
fclose(fp2);
return(0);
} |
|