当前位置:网站首页>C语言读取数据
C语言读取数据
2022-06-26 15:30:00 【X1996_】
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
//下面是写数据,将数字0~9写入到data.txt文件中
FILE *fpWrite1=fopen("out1.txt","w");
FILE *fpWrite2=fopen("out2.txt","w");
FILE *fpRead2=fopen("input2.txt","r");
FILE *fpRead3=fopen("input3.txt","r");
int flag=0;
while(1){
char a[1000];
int res=fscanf(fpRead2,"%s",a);
if(res == EOF)
break;
for(int j=0;a[j]!='\0';j++){
if(a[j]!=','){
fprintf(fpWrite1,"%c",a[j]);
// printf("%c",a[j]);
flag=1;
}else{
if(flag==1){
fprintf(fpWrite1,"%c",'\n');
// printf("\n");
flag=0;
}
}
}
if(flag==1){
// printf("\n");
fprintf(fpWrite1,"%c",'\n');
flag=0;
}
}
flag=0;
while(1){
char a[1000];
int res=fscanf(fpRead3,"%s",a);
if(res == EOF)
break;
for(int j=0;a[j]!='\0';j++){
if(a[j]!=','){
fprintf(fpWrite2,"%c",a[j]);
// printf("%c",a[j]);
flag=1;
}else{
if(flag==1){
fprintf(fpWrite2,"%c",'\n');
// printf("\n");
flag=0;
}
}
}
if(flag==1){
// printf("\n");
fprintf(fpWrite2,"%c",'\n');
flag=0;
}
}
fclose(fpWrite1);
fclose(fpWrite2);
fclose(fpRead2);
fclose(fpRead3);
FILE *fpRead1=fopen("input1.txt","r");
FILE *fpRead_2=fopen("out1.txt","r");
FILE *fpRead_3=fopen("out2.txt","r");
FILE *fpWrite3=fopen("out3.txt","w");
int max=0;
while(1){
char a[100];
int res1=fscanf(fpRead1,"%s",a);
int s=0;
for(int j=0;a[j]!='\0';j++){
s=s*10+(a[j]-'0');
}
if(s>max)
max=s;
if(res1 == EOF )
break;
}
fclose(fpRead1);
printf("最多人数为:%d人\n",max);
FILE *fpRead_1=fopen("input1.txt","r");
char sfz[20]=" ";
while(1){
char a[100];
char b[1000];
char c[1000];
int res1=fscanf(fpRead_1,"%s",a);
int s=0;
for(int j=0;a[j]!='\0';j++){
s=s*10+(a[j]-'0');
}
if(res1 == EOF )
break;
for(int i=0;i<s;i++){
int res2=fscanf(fpRead_2,"%s",b);
int res3=fscanf(fpRead_3,"%s",c);
fprintf(fpWrite3,"%s",b);
fprintf(fpWrite3,"%c",',');
fprintf(fpWrite3,"%s",c);
if(i!=max-1)
fprintf(fpWrite3,"%c",',');
}
for(;s<max;s++){
fprintf(fpWrite3,"%s"," ");
fprintf(fpWrite3,"%c",',');
fprintf(fpWrite3,"%s",sfz);
if(s!=max-1)
fprintf(fpWrite3,"%c",',');
}
fprintf(fpWrite3,"%c",'\n');
}
fclose(fpWrite3);
fclose(fpRead_1);
fclose(fpRead_2);
fclose(fpRead_3);
return 0;
}
边栏推荐
- 手机上怎么开户?在线开户安全么?
- On which platform is it safe to buy shares and open an account? Ask for guidance
- 音视频学习(二)——帧率、码流和分辨率
- Is it safe to open an account for mobile stock registration? Is there any risk?
- Audio and video learning (III) -- SIP protocol
- 7 自定义损失函数
- 全面解析Discord安全问题
- Keil4 opens the single-chip microcomputer project to a blank, and the problem of 100% program blocking of cpu4 is solved
- 【leetcode】701. 二叉搜索树中的插入操作
- 音视频学习(一)——PTZ控制原理
猜你喜欢
随机推荐
Svg canvas canvas drag
SVG大写字母A动画js特效
TweenMax+SVG切换颜色动画场景
Canvas three dot flashing animation
Use of abortcontroller
Summer camp is coming!!! Chongchongchong
零知识 QAP 问题的转化
CNN优化trick
Summary of students' learning career (2022)
Nanopi duo2 connection WiFi
Golang 1.18 go work usage
JS handwritten bind, apply, call
【leetcode】48. Rotate image
Svg capital letter a animation JS effect
How to handle 2gcsv files that cannot be opened? Use byzer
Anaconda3安装tensorflow 2.0版本cpu和gpu安装,Win10系统
JS events
学习内存屏障
Secure JSON protocol
JS creative icon navigation menu switch background color









