小弟初学C不久,遇到一个指针函数程序的问题望大家帮忙看看什么地方有错 它其实就是谭浩强课本中的例子:有若干学生的成绩,每个学生4门课程,要求在用户输入学生序号以后能输出该学生的全部成绩,用指针函数来实现。 编译中错误提示不明白,望大家指点指点,感谢!
#include"stdio.h" main() {static float score[][4]={{60,70,80,90},{45,66,54,54},{45,35,94,65}}; float * search(); float * p; int i,m; printf("enter the number of students:"); scanf("%d",&m); printf("the scores of No.%d are :\n",m); p=search(score,m); //<-------此行有错误:error C2660: 'search' : function does not take 2 parameters// for(i=0;i<4;i++) printf("5.2f\t",*(p+i)); }
float * search(float (* pointer)[4],int n) {float * pt; pt=* (pointer+n); return (pt); }
----------------解决方案--------------------------------------------------------
#include"stdio.h" main() {static float score[][4]={{60,70,80,90},{45,66,54,54},{45,35,94,65}}; float * search(); float * p; int i,m; printf("enter the number of students:"); scanf("%d",&m); printf("the scores of No.%d are :\n",m); p=search(score,m); for(i=0;i<4;i++) printf("%.2f\t",*(p+i));getch(); }
float * search(float (* pointer)[4],int n) {float * pt; pt=* (pointer+n-1); return (pt); }
----------------解决方案--------------------------------------------------------
function does not take 2 parameters search函数不能带两个参数
----------------解决方案--------------------------------------------------------
#include"stdio.h"
float * search(float (* pointer)[4],int n) {float * pt; pt=* (pointer+n-1); return (pt); }
main() {static float score[][4]={{60,70,80,90},{45,66,54,54},{45,35,94,65}}; float * p; int i,m; printf("enter the number of students:"); scanf("%d",&m); printf("the scores of No.%d are :\n",m); p=search(score,m); for(i=0;i<4;i++) printf("%.2f\t",*(p+i));getch(); } 这样应该没问题吧!
----------------解决方案--------------------------------------------------------
看来只有将来再解决啦!!
----------------解决方案--------------------------------------------------------