从TXT文本读取资料时出错
#include<stdio.h>#include<stdlib.h>
#include<string.h>
typedef struct
{
char name[10];
char sex[2];
char schoolname[10];
float result;
int score;
}data;
void main()
{
int i=0,j;
data P[10];
int scoresf[5]={0},scoresm[5]={0},scorest[5]={0};
FILE *fr;
fr=fopen("成绩数据.txt","r");
if(fr==NULL)
{
printf("file open error!\n");
exit(0);
}
else printf("success\n");//测试
while(!feof(fr))
{
fscanf(fr,"%s %s %s %f %d\n",&P[i].name,&P[i].sex,&P[i].schoolname,&P[i].result,&P[i].score);
i++;
}
/* for(j=0;j<i;j++)
{
}*/
/* for(j=0;j<i;j++)
{
if(P[j].schoolname=="A")
scorest[0]+=P[j].score;
if(P[j].schoolname=="B")
scorest[1]+=P[j].score;
}printf("%d",scorest[0]);*/
fclose(fr);
}
文本里的内容:
ling f A 10 5
ling m A 10 5
ling f B 10 3
ling m B 10 3