#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<math.h>
struct STU
{
char id[15];
char name[15];
char zhuanye[20];
int sc1;
int sc2;
int sc3;
int sc4;
int sc5;
int sum;
};
struct STU stu[200];
int input(char *in,struct STU *p);
void p_int(int n,struct STU *p);
void youxiu(int n,struct STU *p);
void main()
{
int m;
m=input("stu.txt",stu);
p_int(m,stu);
youxiu(m,stu);
}
int input(char *in,struct STU *p)//输入
{
char a[200];
int i;
FILE *fp;
if((fp=fopen(in,"r"))==NULL)
{
printf("\t \t未找到文件!\n");
exit(1);
}
for(i=0;i<1;i++)
{
fgets(a,200,fp);
}
i=0;
while(!feof(fp))
{
fscanf(fp,"%s%s%s%d%d%d%d%d",p[i].id ,p[i].name ,p[i].zhuanye ,
&p[i].sc1 ,&p[i].sc2 ,&p[i].sc3,&p[i].sc4,&p[i].sc5);
i++;
}
return i;
}
void p_int(int n,struct STU *p)//输出到屏幕
{
int i,s_sum;
printf(" 学号 姓名 专业 C语言 计算物理学 大学物理 原子物理 光学\n");
for(i=0;i<n-1;i++)
{
s_sum=p[i].sc1+p[i].sc2+p[i].sc3+p[i].sc4+p[i].sc5;
printf("%-15s%-15s%-15s%-6d%-6d%-6d%-6d%-6d%-6d\n",p[i].id ,p[i].name ,p[i].zhuanye ,
p[i].sc1 ,p[i].sc2 ,p[i].sc3,p[i].sc4,p[i].sc5,s_sum);
}
}
void youxiu(int n,struct STU *p)
{
int i,count;
for(i=0;i<n;i++)
{
count=0;
if(p[i].sc1 >85)
{
count++;
break;
}
if(p[i].sc2 >85)
{
count++;
break;
}
if(p[i].sc3 >85)
{
count++;
break;
}
if(p[i].sc4 >85)
{
count++;
break;
}
if(p[i].sc5 >85)
{
count++;
break;
}
printf("*******************\n");
// if(count>0)
printf("%-15s%-15s\n该同学优秀科目为%d\n",p[i].id ,p[i].name ,count);
// else if(count==0)
// printf("%-15s%-15s\n该同学没有优秀",p[i].id ,p[i].name);
}
}
输出不了每个人的优秀科目qwq,请教各位大神
不知道你这个问题是否已经解决, 如果还没有解决的话: