当前位置:网站首页>The two files are merged into a third file.
The two files are merged into a third file.
2022-06-26 19:27:00 【laocooon】
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define MAX 1024
#define F1 "f1.txt"
#define F2 "f2.txt"
#define F3 "f3.txt"
void strcat(char* s1, char *s2,char *s3)// Alternate arrangement of generated strings s3
{
int i = 0,j=0,k=0;
while (s1[i] && s2[j])
{
s3[k++] = s1[i++];
s3[k++] = s2[j++];
}
while (s1[i])
{
s3[k++] = s1[i++];
}
while (s2[j])
{
s3[k++] = s2[j++];
}
s3[k] = '\0';
}
void printfile(char *filename)
{
char s[1024];
FILE* fp;
fp = fopen(filename, "r");
if (fp == NULL)
return;
printf("%s Is as follows :\n",filename);
while (fscanf(fp, "%s", s) != EOF)
{
printf("%s\n",s);
}
fclose(fp);
}
void merge(char *file1, char* file2, char* file3)
{
char s1[1024], s2[1024], s3[2048];
int tmp1,tmp2;
FILE* f1, * f2, * f3;
f1 = fopen(file1, "r");
f2 = fopen(file2, "r");
f3 = fopen(file3, "w");
if (f1 == NULL || f2 == NULL || f3 == NULL)// If three files One of the failed to open , immediate withdrawal
return ;
while (1)
{
tmp1 = fscanf(f1, "%s", s1);
tmp2 = fscanf(f2, "%s", s2);
if (tmp1 == EOF && tmp2 == EOF)
break;
else if (tmp1 != EOF && tmp2 != EOF)
{
strcat(s1, s2, s3);
fprintf(f3, "%s\n", s3); }
else if (tmp2 != EOF)
{
printf(f3, "%s\n", s2);
}
else if (tmp1 != EOF)
{
fprintf(f3, "%s\n", s1);
}
}
fclose(f1);
fclose(f2);
fclose(f3);
}
int main()
{
printfile(F1);
printfile(F2);
merge(F1,F2,F3);
printfile(F3);
return 0;
}边栏推荐
- Example of using QPushButton style (and method of adding drop-down menu to button SetMenu)
- Development principle analysis and source code of dapp-lp single and dual currency liquidity pledge mining system
- vuex中利用缓存解决刷新state数据丢失问题
- 深度学习之Numpy篇
- Deep learning: numpy
- On the escape of inequality value
- 最小生成树、最短路径、拓扑排序、关键路径
- 刷新三观的HP-UX系统中的强指针赋值出core问题
- Publish message publishers and subscribe message subscribers of ROS
- xlua获取ugui的button注册click事件
猜你喜欢

Project practice 5: build elk log collection system

Pinda general permission system (day 1~day 2)

Wechat applet custom pop-up components

关于不等式取值转义的思路

关于Qt数据库开发的一些冷知识

抖音实战~分享模块~生成短视频二维码

stm32和电机开发(直流有刷电机和步进电机)

黑客用机器学习发动攻击的九种方法

Decompilation of zero time technology smart contract security series articles

50 lines of code to crawl TOP500 books and import TXT documents
随机推荐
Preliminary analysis of serial port printing and stack for arm bare board debugging
stm32和电机开发(直流有刷电机和步进电机)
Analysis on development technology of NFT meta universe chain game system
Vscode 基础必备 常用插件
The goal you specified requires a project to execute but there is no POM
Kubernetes 资源拓扑感知调度优化
项目实战六:分布式事务-Seata
Wechat applet uniapp left slide delete with Delete Icon
System table SQLite of SQLite database_ master
Redis Basics
成功解决之微服务@Value获取配置文件乱码问题
关于不等式取值转义的思路
微服务版单点登陆系统(SSO)
Why don't I recommend going to sap training institution for training?
Record of user behavior log in SSO microservice Engineering
Boot indicator monitoring
转:苹果CEO库克:伟大的想法来自不断拒绝接受现状
字符串String转换为jsonArray并解析
uni-app使用canvas绘制二维码
Solidity - contract inheritance sub contract contains constructor errors and one contract calls the view function of another contract to charge gas fees