/data/user/0/com.chenghui.study.c/files/temp.c: In function 'int main()':
/data/user/0/com.chenghui.study.c/files/temp.c:21:33: error: expected primary-expression before ']' token
minmax(stu[stu_n].chinese, res[]);
^
你函数参数要求是素组,但你却传递了一个语文课成绩。当然不行了。第二个参数应该传递res,加中括号也是不对的
建议你将结构修改为成绩数组,然后minmax传递stu及课程序号
修改如下:
#include <stdio.h>
#define stu_n 10
typedef struct {
char name[20];
int score[5];
}STU;
char *s[5] = {"chinese","math","english","physics","chemistry"};
void minmax(STU *p,int n,int *res);
int main()
{
STU stu[stu_n]
int res[2],i;
for(i=0;i<stu_n;i++)
scanf("%s%d%d%d%d%d",stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2],&stu[i].score[3],&stu[i].score[4]);
minmax(stu,0,res);
printf("max %d min %d",res[1],res[0]);
return 0;
}
void minmax(STU *p,int n,int *res)
{
int min=1000,max=0,i;
for(i=0;i<stu_n;i++)
{
if(min > p[i].score[n])
min = p[i].score[n];
if(max < p[i].score[n])
max = p[i].score[n];
}
res[0] = min;
res[1] = max;
}
你是用结构体数组存放每个人的数据,不能直接使用minmax(stu[stu_n].chinese这种写法来取每个人的对应科目成绩
你需要将stu数组整个传入并判断其中每个结构体中存放的成绩
后面的res[]应改为res