[求助]为什么这个程序运算不正确
计算一组学生的平均成绩和不及格人数。用结构指针变量作函数参数编程struct stu
{
int num;
char* name;
char sex;
float score;
}boy[5]={
{101,"li ming",'B',88.5},
{102,"wang lu",'G',92.3},
{103,"zhang tian",'B',58},
{104,"lu ming",'B',34},
{105,"fu li",'G',84},
};
main()
{
int i;
struct stu* ps;
void avge(struct stu* ps);
ps=boy;
for(i=0;i<5;i++,ps++)
printf("%d\t%s\t%c\t%f\n",ps->num,ps->name,ps->sex,ps->score);
avge(ps);
getch();
return;
}
void avge(struct stu* ps)
{
int i,c=0;
float k=0,sum;
for(i=0;i<5;i++,ps++);
{
sum+=ps->score;
if(ps->score<60)
c++;
}
printf("sum=%f\n",sum);
k=sum/5;
printf("avge=%f\tc=%d\n",k,c);
}
为什么输出的结果不是我想要的。