#include<stdio.h>
#include <string.h>
typedef struct worker{
char name[100];
char sex[100];
int date;
char type[100];
}worker;
const int n = 5;
int main(){
void input(worker *st, int a);
void judge(worker *st, int a);
void output(worker *st, int a);
worker st[n];
worker *wk = st;
input(wk, n);
judge(wk, n);
output(wk, n);
return 0;
}
void input(worker *st, int a){
int j;
for (j = 0; j < a; j++){
scanf("%s %s %d", st[j].name, st[j].sex, &st[j].date);
}
}
void judge(worker *st, int a){
int j;
for (j = 0; j < a; j++){
if (st[j].date<0.5){
strcpy(st[j].type, "正常");
}
else{
strcpy(st[j].type, "不正常");
}
}
}
void output(worker *st, int a){
int j;
for (j = 0; j < a; j++){
printf("%s,%s,%d,%s\n", st[j].name, st[j].sex, st[j].date, st[j].type);
}
}
将如下的代码改为用文件读取结构体,并且将显示正常的结构体输出到一个文件,显示不正常输出到另一个文件?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
CSDN专家-赖老师(软件之家) 2021-06-10 16:23关注没看到有文件操作的代码,是要增加文件操作吗?
FILE * fp; fp = fopen("students.txt", "at+"); //以"追加"方式打开students文本文件 fwrite( & student[i], sizeof(struct students), 1, fp); fclose(fp);评论 打赏 举报解决 1无用