C语言结构体作为函数参数问题

liuyuanyang 2008-05-17 10:58:32
一个学生信息管理系统;单独做一个函数引用结构体,请问在C 语言中结构体如何被函数引用?
写了一点点,但是有错:
#include<stdio.h>
void total(struct)
{
struct student;
int i;
for(i=0;i<3;i++)
student[0].total+=student[0].b[i];

}


void main()
{
struct a
{
int b[3];
int total;
int avg;
};
struct a student[1] ={
{ 23,45,65 }
};
total(student);
printf("total is %d\n",student[0].total);
return(0);

}
...全文
237 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Supercaller 2008-05-25
  • 打赏
  • 举报
回复
思路是这样的,但是我是在这里写的,没有运行,如果还有问题,自己应该很快就能找出
#include <stdio.h>
struct a
{
int b[3];
int total;
int avg;
};

int total(struct a student)
{
int i;
student.total=0;

for(i=0;i <3;i++)
{
student.total+=student.b[i];

}
return student.total;
}
void main()
{
struct a student1;
student1.b={23,45,65};
printf("total is %d\n",student1.total);
return 0;
}

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧