菜鸟求救:我的程序怎么总益出?
我的程序很简单,就是用一个指针来读取一个3X4的数组中的数据,可在运行search函数时,总是报错 益出,而aver函数就没问题,大家看一下把!
main()
{float aver(float *p,int n);
float search(float (*p)[4],int n);
float score[3][4]={{67,65,70,60},{80,87,90,81},{90,99,100,98}};
aver(score[0],12);
search(score,n);
}
float aver(float *p,int n)
{float*p_end;
float sum=0,aver;
p_end=p+n-1;
for(;p<=p_end;p++)
{sum=sum+(*p);}
aver=sum/n;
printf("average is %f\n",aver);
}
float search(float (*p)[4],int n)
{int i;
printf("the score of No.%d is :",n);
for(i=0;i<4;i++)printf("%.2f",*(*(p+n)+i));
}
对了,我用的是TC