结构体数组的调用函数问题

我定义了一个struct student
{
int xh;
char name[10];
float ms;
float es;
float cs;
float ave;
float tot;
};
void xs();
void main()
{
student a[30];
}
void xs()
那个调用函数该怎样写才能够在函数里用a[i].xh之类的

这个函数这样定义就可以了:
void xs(student *ptr,int num);//其中ptr为一个指向student的指针,num为元素的个数。

调用该函数的语句为
xs(a,30);

//xs()函数
void xs(student *ptr,int num)
{
for(int i=0;i<num;++i)
{
ptr[i].xh=10;//在这个循环里面就可以进行操作了,ptr与a操作同一块内存。
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-23
你说的调用函数是xs?
如果是的话你2种方法,1是把你的student对象a[30]传递到函数中,第2,你在xs里面自己再定义一个student的对象
第2个回答  2010-05-23
struct student
{
int xh;
char name[10];
float ms;
float es;
float cs;
float ave;
float tot;
}student;

末尾加个这个就可以了
相似回答