3个回答
展开全部
#include "stdio.h"
/*******************************************
*文件复制函数
*输入参数:FILE * sf--源文件指针
FILE *df--目标文件指针
*输出:0-成功;非0-失败
*******************************************/
int FileCopy(FILE * sf,FILE * df)
{
int i_result;
char ch_Buffer[512];
int num_read,num_write;
i_result = 0;
while(NULL != (num_read = (fread(ch_Buffer,sizeof(char),sizeof(ch_Buffer),sf)))
{
num_write = fwrite(ch_Buffer,num_read,1,df);
if (num_write != nub_read)
{
i_result = 3;
}
}
}
/*******************************************
*主函数
*******************************************/
void main(void)
{
FILE *f1;
FILE *f2;
int i_return;
i_return = 0;
if (NULL != (f1 =fopen("JJ.TXT","r")))
{
if (NULL != (f2 =fopen("aa.TXT","w+")))
i_return = FileCopy(f1,f2);
else
i_return = 2;
}
else
i_return = 1;
switch (i_return)
{
case 1:
printf ("源文件打开失败!\n");
break;
case 2:
printf ("目标文件打开失败!\n");
break;
case 3:
printf ("文件复制失败!\n");
break;
}
}
/*******************************************
*文件复制函数
*输入参数:FILE * sf--源文件指针
FILE *df--目标文件指针
*输出:0-成功;非0-失败
*******************************************/
int FileCopy(FILE * sf,FILE * df)
{
int i_result;
char ch_Buffer[512];
int num_read,num_write;
i_result = 0;
while(NULL != (num_read = (fread(ch_Buffer,sizeof(char),sizeof(ch_Buffer),sf)))
{
num_write = fwrite(ch_Buffer,num_read,1,df);
if (num_write != nub_read)
{
i_result = 3;
}
}
}
/*******************************************
*主函数
*******************************************/
void main(void)
{
FILE *f1;
FILE *f2;
int i_return;
i_return = 0;
if (NULL != (f1 =fopen("JJ.TXT","r")))
{
if (NULL != (f2 =fopen("aa.TXT","w+")))
i_return = FileCopy(f1,f2);
else
i_return = 2;
}
else
i_return = 1;
switch (i_return)
{
case 1:
printf ("源文件打开失败!\n");
break;
case 2:
printf ("目标文件打开失败!\n");
break;
case 3:
printf ("文件复制失败!\n");
break;
}
}
展开全部
void main()
{
FILE *fr, *fw;
int ch;
if( NULL == (fr=fopen("jj.txt","r")) )
{
printf("Open file error!\n");
exit(-1);
}
if( NULL == (fr=fopen("aa.txt","w")) )
{
printf("Open file error!\n");
exit(-1);
}
while( EOF!=(ch=getc(fr)) )
{
putc(ch,fw);
}
if( fclose(fr) )
{
printf("file jj.txt not closed!\n");
}
if( fclose(fw) )
{
printf("file jj.txt not closed!\n");
}
}
附:如果就只是重命名,使用system命令允许一个批处理文件就可以了。
{
FILE *fr, *fw;
int ch;
if( NULL == (fr=fopen("jj.txt","r")) )
{
printf("Open file error!\n");
exit(-1);
}
if( NULL == (fr=fopen("aa.txt","w")) )
{
printf("Open file error!\n");
exit(-1);
}
while( EOF!=(ch=getc(fr)) )
{
putc(ch,fw);
}
if( fclose(fr) )
{
printf("file jj.txt not closed!\n");
}
if( fclose(fw) )
{
printf("file jj.txt not closed!\n");
}
}
附:如果就只是重命名,使用system命令允许一个批处理文件就可以了。
展开全部
char buffer[512];
FILE *fp1,*fp2;
float num;
if(NULL==(fp1=fopen("JJ.TXT","r")))
{
printf("失败\n");
}
else
{
while((num=fread(buffer,sizeof(char),sizeof(buffer),fp1))!=NULL)
{
if(NULL==(fp2=fopen("aa.TXT","w+")))
{
printf("错误\n"); }
else
{
if((num!=fwrite(buffer,num,1,fp)))
{
printf("失败");
}
else
{
fclose(fp2);
}
fclose(fp1);
printf("SUCCESS!\n");
}
}
}
FILE *fp1,*fp2;
float num;
if(NULL==(fp1=fopen("JJ.TXT","r")))
{
printf("失败\n");
}
else
{
while((num=fread(buffer,sizeof(char),sizeof(buffer),fp1))!=NULL)
{
if(NULL==(fp2=fopen("aa.TXT","w+")))
{
printf("错误\n"); }
else
{
if((num!=fwrite(buffer,num,1,fp)))
{
printf("失败");
}
else
{
fclose(fp2);
}
fclose(fp1);
printf("SUCCESS!\n");
}
}
}
本回答被网友采纳
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询