#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);
}
}
没看到有文件操作的代码,是要增加文件操作吗?
FILE * fp;
fp = fopen("students.txt", "at+"); //以"追加"方式打开students文本文件
fwrite( & student[i], sizeof(struct students), 1, fp);
fclose(fp);
你的意思是,input()那里参数改为文件,然后output()那里输出的printf改为根据type的值输出到俩文件里?
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632