结构体问题
# include <stdio.h># define M 10
typedef struct
{
char num [10];
double s;
}SCORE;
double fun(SCORE *c,SCORE *l,int *n)
{
int i,j=0;
double aver=0.0;
for(i=0; i<M; i++)
aver+=c[i].s;
aver/=M;
for(i=0; i<M; i++)
if(c[i].s<=aver)
{
*(l+j)=c[i];
j++;
}
*n=j;
return aver;
}
main ()
{
SCORE stu[M]={{"03",76},{"02",69},{"04",85},{"01",91},{"07",72},{"08",64},{"06",87},{"09",60},{"11",79},{"12",73}};
SCORE low [M],t;
FILE *out ;
int i,j,n;
double ave;
ave=fun(stu,low,&n);
printf("The %d student data which is lower than %7.3f:\n",n,ave);
for(i=0;i<n;i++)
printf("%s %4.1f\n",low[i].num,low[i].s);
printf("\n");
out=fopen("outfile.dat","w");
fprintf(out,"%d\n%7.3f\n",n,ave);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(low[i].s<low[j].s)
{
t=low[i];
low[i]=low[j];
low[j]=t;
}
for(i=0;i<n;i++)
fprintf(out,"%4.1f\n",low[i].s);
fclose(out);
}
谁能帮我解释一下红色字体中c[i]为什不能换成c[i].s?
对不住,现在真的没分了。