#include
#include
typedef struct student
{char num[10];
double score;
} strec ;
int fun(student*, int, student**,int,int);
int main()
{
strec s[5]={{"0001",90} ,{"0002",80.0},{"0003",70},{"0004",60},{"0005",50}};
strec *b;
int count = fun(s,5, &b, 60, 90);
for(int i = 0; i < count; i ++)
{
printf("%s %.2f\n", b[i].num, b[i].score);
}
}
int fun(strec* a,int num, strec **b,int l,int h)//l,h表示分数范围,第二个int表示传入a数组的元素个数
{
int count = 0;
strec * re = new strec[num];
for(int i = 0; i < num; i ++)
{
if(a[i].score >= l && a[i].score <= h)
{
count++;
re[i].score = a[i].score;
strcpy(re[i].num, a[i].num);
}
}
*b = re;
return count;
}
对你的函数修改了一下
int fun(student*, int, student**,int,int); //添加了一个int,第三个参数改为传入b的地址。
在vs 2008测试运行过了,结果如下:
0001 90.00
0002 80.00
0003 70.00
0004 60.00
请按任意键继续. . .