当前位置:网站首页>6-8 有结构文件的读写1
6-8 有结构文件的读写1
2022-06-11 17:17:00 【西红柿_码农】
学生类型:ST的类型定义如下:
typedef struct student{ char name[10],id[10]; int gender; int age; double scored; } ST; 编写函数,从指定的文件上读入若干字符串,每行字符串是一个学生的信息(姓名,学号,性别,年龄,分数)的字符串表示,数据间以空格分隔,将学生们的信息存储于一个结构体中,并利用output()函数输出到指定文件中。
函数接口定义:
void fun(FILE *fin,FILE *fout);其中 fin 和 fout 都是用户传入的参数。 前者是已正常打开的可读文件,而后者是已正常打开的可写文件。
裁判测试程序样例:
在这里给出函数被调用进行测试的例子。例如:
#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){//测试程序,输出到文件调用此函数完成
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);//<--需要完成的函数(包括读入字符串,转换成对应的结构体,并利用函数(output())输出到指定文件中,输入输出文件不用考虑
/* 请在这里填写答案 */输入样例:
从固定文件中读取:文件内容:
aaa 123 0 18 88.88
bbb 456 1 19 99.99
ccc 789 1 18 66.66
ddd 356 0 18 67.89
输出样例:
输出到指定文件中,文件内容:
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));
//注意,id要用%s,因为防止0XX的情况,该情况是无法用%d读取
}
边栏推荐
- 满k叉树编号为 i 的节点的孩子编号公式推导
- Go get downloaded package path
- Authing CEO 谢扬入选福布斯 2021 年 30 Under 30 亚洲榜单
- mysql 大表的拆分方式
- ASP. Net education OA system source code education industry OA system source code with document
- JSP page initial loading method
- 我的CのERROR们
- Intranet penetration based on UDP port guessing
- Xie Yang, CEO of authing, was selected into Forbes' 30 under 30 Asia list in 2021
- Axi protocol Basics
猜你喜欢

使用exe4j 将.jar文件打包为.exe文件

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

定制 or 订阅?未来中国 SaaS 行业发展趋势是什么?

QLineEdit 设置输入掩码

How to become an optimist organization?

Vscode automatic eslint formatting when saving code

vscode保存代碼時自動eslint格式化

Semaphore PV operation of process interaction and its code implementation

Solr (I) installation and permission control of Solr

子类继承了什么、多态、 向上转型
随机推荐
从制造到“智造”,探索制造企业破局之道
ffmpeg硬件编解码Nvidia GPU
TypeScipt基础
String to numeric value
[pytest learning] after the pytest case fails to execute, the others will not be executed
From manufacturing to "intelligent manufacturing", explore the way for manufacturing enterprises to break the situation
Katalon Studio Enterprise
Environment configuration and pymysql installation
vscode配置eslint自动格式化报错“The setting is deprecated. Use editor.codeActionsOnSave instead with a source“
vscode配置eslint自动格式化报错“Auto Fix is enabled by default. Use the single string form“
拜登下令强制推行零信任架构
sql server中关于FORCESCAN的使用以及注意项
Custom or subscription? What is the future development trend of China's SaaS industry?
ffmpeg奇偶场帧Interlace progressive命令和代码处理
Authing 背后的计算哲学
LeetCode——42. Connected to rainwater (double pointer)
Authoring share | understanding saml2 protocol
How to become an optimist organization?
活动 | Authing 首次渠道合作活动圆满落幕
mysql 大表的拆分方式