关于C中结构体问题

[复制链接]
查看11 | 回复1 | 2009-3-26 18:34:23 | 显示全部楼层 |阅读模式
#include
#defineN12
typedefstruct
{
charnum [10];
doubles;
}STREC;
doublefun( STREC*a,STREC*b,int*n )
{
int i,c=0;
double avar=0.0;
for(i=0;i=avar)
b[c++]=a;//这里的a为什么不是a.s??
*n=c;
return avar;
}
main ()
{
STRECs[N]={{"GA05",85}, {"GA03",76}, {"GA02",69}, {"GA04",85},
{"GA01",91}, {"GA07",72}, {"GA08",64}, {"GA06",87},
{"GA09",60}, {"GA11",79}, {"GA12",73}, {"GA10",90}};
STRECh [N], t;
FILE*out ;
inti,j,n;
doubleave;
ave=fun ( s, h, &n );
printf ( "The %d student data which is higher than %7.3f:\n", n, ave);
for ( i=0; i<n; i++ )
printf("%s%4.1f\n", h. num, h. s);
printf ("\n");
out=fopen("out.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(h.s<h[j].s)
{

t=h ;

h=h[j];

h[j]=t;
}
for(i=0;i<n; i++)
fprintf(out, "%4.1f\n",h.s);
fclose(out);
}

回复

使用道具 举报

千问 | 2009-3-26 18:34:23 | 显示全部楼层
double fun ( STREC *a, STREC *b, int *n ) ;说明中,指定了b为STREC *类型的,而a.s是double类型的,当然不能相互传值了....
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行