C语言实现两个文件的连接

 时间:2024-10-23 18:34:23

两个文件连接的意思就是将一个文件的数据,添加到另一个文件数据内容的后面

方法/步骤

1、首先打开VC++6.0

C语言实现两个文件的连接

2、选择文件,新建

C语言实现两个文件的连接

3、选择C++sourcefile新建一个空白文档

C语言实现两个文件的连接

4、先声明头文件#include<stdio.h>

5、函数,输出文件内容voidOutputFile(FILE*fp){charch;while((ch=fgetc(fp))!=EOF)putchar(ch);}

C语言实现两个文件的连接

6、文件连接函数voidJoinFile(char咯悝滩镞*sfilename,char*dfilename){charch;FILE*fp1,*fp2;/*进行输淀尬逄攻入重定向*/if((fp1=freopen(sfilename,"r",stdin))==0){printf("Can'topenthefile:%s\n",sfilename);return;}/*进行输出重定向*/if((fp2=freopen(dfilename,"a",stdout))==0){printf("Can'topenorcreatethefile:%s\n",dfilename);return;}/*进行文件的读写*/while((ch=getchar())!=EOF)putchar(ch);fclose(fp1);fclose(fp2);return;}

C语言实现两个文件的连接

7、主函数intmain(拘七呷憎){charsfilename[20];chardfilename[20];FILE*sfp,*dfp;printf("**********忮氽阝另************************************\n");printf("|Theprogramwilljoinafiletoanother!|\n");printf("|Youcanopentheobjectfiletoverifythis!|\n");printf("**********************************************\n");/*得到要被连接的文件名*/printf("\nPleaseinputsourcefilename:\n");gets(sfilename);/*得到要连接到的文件的文件名*/printf("Pleaseinputdestinationfilename:\n");gets(dfilename);/*输出连接前文件的内容*/if(((sfp=fopen(sfilename,"r"))==0)||((dfp=fopen(dfilename,"r"))==0))return0;printf("\nThetextofthefile%sbeforejoining:\n",sfilename);OutputFile(sfp);printf("\nThetextofthefile%sbeforejoining:\n",dfilename);OutputFile(dfp);printf("\nPleaseopenthefile%stoverifythetext!\n",dfilename);getch();/*连接两个文件*/JoinFile(sfilename,dfilename);fclose(sfp);fclose(dfp);return0;}

C语言实现两个文件的连接

C语言:相同整型变量的定义与使用的示例 linux 中打印水仙花数字 360极速浏览器X怎么设置禁用操作系统虚拟键盘 js如何实现3d饼状图 eclipse中的devices关闭了如何调出来
热门搜索
拐杖图片 图片大全唯美 在线成人漫画 打坐图片 几米漫画