当前位置:网站首页>6-8 reading and writing of structured files 1
6-8 reading and writing of structured files 1
2022-06-11 17:37:00 【Tomatoes_ Menon】
Student type :ST The types of are defined as follows :
typedef struct student{ char name[10],id[10]; int gender; int age; double scored; } ST; Write function , Read several strings from the specified file , Each line of string is a student's information ( full name , Student number , Gender , Age , fraction ) String representation of , The data room is marked with Space Separate , Store students' information in a structure , And make use of output() Function to the specified file .
Function interface definition :
void fun(FILE *fin,FILE *fout); among fin and fout All parameters passed in by the user . The former is a readable file that has been opened normally , The latter is a normally opened writable file .
Sample referee test procedure :
Here is an example of a function being called for testing . for example :
#include <stdio.h>
#include <stdlib.h>
typedef struct student{
char name[10],id[10];
int gender;
int age;
double scored;
} ST;
void output(ST *d,FILE *fout){// The test program , Output to file call this function to complete
if(d==NULL) {printf("null\n");return;}
fprintf(fout,"%s,%s,%d,%d,%4.2f\n",d->name,d->id,d->gender,d->age,d->scored);
}
void fun(FILE *fin,FILE *fout);//<-- Functions to be completed ( Including read in string , Convert to the corresponding structure , And use function (output()) Output to the specified file , Input and output files do not need to be considered
/* Please fill in the answer here */sample input :
Read from fixed file : The contents of the document :
aaa 123 0 18 88.88
bbb 456 1 19 99.99
ccc 789 1 18 66.66
ddd 356 0 18 67.89
sample output :
Output to the specified file , The contents of the document :
aaa,123,0,18,88.88
bbb,456,1,19,99.99
ccc,789,1,18,66.66
ddd,356,0,18,67.89void fun(FILE *fin,FILE *fout)
{
for(ST s;fscanf(fin,"%s%s%d%d%lf",s.name,s.id,&s.gender,&s.age,&s.scored)!=EOF;output(&s,fout));
// Be careful ,id Use %s, Because of prevention 0XX The situation of , This condition is not available %d Read
}
边栏推荐
- Authoring share | understanding saml2 protocol
- Authing biweekly news: authing forum launched (4.25-5.8)
- Mathematical foundations of information security Chapter 3 - finite fields (II)
- Service学习笔记03- 前台服务实战
- 7-2 h0107. Pig-Latin
- Automated testing selenium
- 活动 | Authing 首次渠道合作活动圆满落幕
- ffmpeg CBR精准码流控制三个步骤
- Chorus translation
- 自动化测试-Selenium
猜你喜欢

活动 | Authing 首次渠道合作活动圆满落幕

which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_ mod

【深度学习基础】神经网络的学习(3)

adb 命令学习笔记

合并两个有序链表---2022/02/24

What problems are exposed when all Sohu employees are cheated?

端口规划与APJ

Threejs uses indexeddb cache to load GLB model
![[foundation of deep learning] learning of neural network (3)](/img/a5/1b80ba85faf8fa636b784c76d4df2f.png)
[foundation of deep learning] learning of neural network (3)

Leetcode force deduction question
随机推荐
Tidb GC related problems
Windows technology - how to view the instruction set, model, attribute and other details supported by the CPU, and how to use the CPU-Z tool to view the processor, memory, graphics card, motherboard,
使用exe4j 将.jar文件打包为.exe文件
Delete the penultimate node of the linked list ---2022/02/22
Typescipt Basics
聚类方法汇总
Service学习笔记02-实战 startService 与bindService
定制 or 订阅?未来中国 SaaS 行业发展趋势是什么?
Difference between require and ES6 import
spawn ./ gradlew EACCES at Process. ChildProcess._ handle. onexit
tidb-数据误删恢复的几种方式
6-3 读文章(*)
How to simplify a lot of if... Elif... Else code?
tidb-gc相关问题
Merge two ordered linked lists ---2022/02/24
CLP information -5 keywords to see the development trend of the financial industry in 2022
[foundation of deep learning] learning of neural network (3)
Service学习笔记01-启动方式与生命周期
Speed adjustment of tidb DDL
6-2 多个整数的逆序输出-递归