当前位置:网站首页>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“
- tidb-cdc日志tables are not eligible to replicate
- Hash table, inheritance
- 7-1 均是素数
- Mathematical basis of information security Chapter 4 -- quadratic residual and square root
- Dynamic: capturing network dynamics using dynamic graph representation learning
- 04_ Feature engineering feature selection
- Typescipt Basics
- ffmpeg硬件编解码Nvidia GPU
- 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
猜你喜欢

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

Summary of clustering methods

ffmpeg硬编解码 Inter QSV

Kubernetes deploys elk and collects container logs using filebeat

Qlineedit set input mask

Test and analysis of tidb write hotspot

删除链表的倒数第N个节点---2022/02/22
![[online problem] timeout waiting for connection from pool](/img/f0/7e8444ed7d0921b98d5e998e274bc8.png)
[online problem] timeout waiting for connection from pool

ffmpeg硬件编解码Nvidia GPU

Use exe4j to convert The jar file is packaged as Exe file
随机推荐
Authing 双周动态:Authing 论坛上线(4.25-5.8)
6-3 读文章(*)
Several ways to recover tidb data from accidental deletion
6-1 read string (*) from file
Merge K ascending linked lists ---2022/02/26
Use exe4j to convert The jar file is packaged as Exe file
Test basis: black box test
6-3 批量求和(*)
[foundation of deep learning] learning of neural network (3)
ADB command learning notes
Speed adjustment of tidb DDL
sql server中移除key lookup书签查找
Remove key lookup bookmark from SQL Server
搜狐全員遭詐騙,暴露哪些問題?
av_read_frame返回值为-5 Input/output error
Hash表、 继承
信息安全数学基础 Chapter 3——有限域(一)
6-1 从文件读取字符串(*)
Go path: goroot & gopath
如何成为一个乐观派组织?