当前位置:网站首页>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
}
边栏推荐
- 搜狐全员遭诈骗,暴露哪些问题?
- vscode配置eslint自动格式化报错“Auto Fix is enabled by default. Use the single string form“
- Xie Yang, CEO of authing, was selected into Forbes' 30 under 30 Asia list in 2021
- Test basis: black box test
- 信息安全数学基础 Chapter 4——二次剩余与方根
- Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单
- Mathematical foundations of information security Chapter 3 - finite fields (I)
- 信息安全数学基础 Chapter 3——有限域(二)
- Authing 双周动态:应用市场上线(5 .10 —5 .22 )
- 6-1 从文件读取字符串(*)
猜你喜欢

vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“

Bentley uses authing to quickly integrate application system and identity

Read and understand the development plan for software and information technology service industry during the "14th five year plan"

Authing 双周动态:应用市场上线(5 .10 —5 .22 )

为什么udp流设置1316字节

From manufacturing to "intelligent manufacturing", explore the way for manufacturing enterprises to break the situation

ffmpeg硬件编解码Nvidia GPU

端口规划与APJ

测试基础之:黑盒测试

Hands on deep learning - multiple input and output channels in the convolution layer
随机推荐
How to become an optimist organization?
Go get downloaded package path
From manufacturing to "intelligent manufacturing", explore the way for manufacturing enterprises to break the situation
[foundation of deep learning] learning of neural network (3)
R language to find missing value location of data set
tidb-写热点的测试及分析
Tidb CDC create task error unknown or incorrect time zone
【深度学习基础】神经网络的学习(3)
There are so many open source projects. This time, I'll show you the differences between different versions and understand the meaning of alpha version, beta version and RC version
require和ES6 import的区别
CentOS7服务器配置(四)---安装redis
Export data prompt -- solution to the problem of secure file priv option
Chorus translation
Foreach traverses collections and collection containers
Chapter II relational database
tidb-cdc日志tables are not eligible to replicate
信息安全数学基础 Chapter 1——整除
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,
搜狐全员遭诈骗,暴露哪些问题?
Hands on deep learning - multiple input and output channels in the convolution layer