69,371
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#define N 50
int maxnum = 0;
typedef struct
{
int Id;
char Name[10];
float TotalScore;
}student;
student Stu[N];
void Load(const char* PATH,student *Stu)
{
FILE *fd;
int i,Flag;
struct temp
{
int Id;
char Name[10];
char Oject[10];
float Score;
}*stu;
fd = fopen(PATH,"r");
while(feof(fd))
{
Flag = 0;
fscanf(fd,"%d",stu->Id);
fscanf(fd,"%s",stu->Name);
fscanf(fd,"%s",stu->Oject);
fscanf(fd,"%s",stu->Score);
for(i = 0;i<maxnum;i++)
if(Stu[i].Id == stu->Id)
{
Stu[i].TotalScore += stu->Score;
Flag++;
}
if(Flag = 0)
{
Stu[maxnum].Id = stu->Id;
strcpy(Stu[maxnum].Name,stu->Name);
Stu[maxnum].TotalScore = stu->Score;
maxnum++;
}
}
fclose(fd);
}
int main()
{
Load("text.txt",Stu);
printf("%d,%s,%d\n",Stu[0].Id,Stu[0].Name,Stu[0].TotalScore);
return 0;
}