酷代码 AI
菜单

6-2 有结构文件的读写1 分数 10 作者 龚雄兴 单位 湖北文理学院 学生类型: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; do

```c #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){ ST student; while (fscanf(fin, "%s %s %d %d %lf", student.name, student.id, &student.gender, &student.age, &student.scored) != EOF) { output(&student, fout); } } ``` [2025-12-25 16:00:51 | AI问答 | 211点数解答]

服务商
相关提问
发财导航,免费问AI
实用工具查看更多