포인터 함수 만드는데 넘 어렵네요...
오류
homework5-3_template.c:11:37: error: parameter ‘a’ has just a forward declaration
homework5-3_template.c:11:24: error: parameter ‘pf’ has just a forward declaration
homework5-3_template.c: In function ‘main’:
homework5-3_template.c:48:2: error: incompatible type for argument 1 of ‘get_root’
homework5-3_template.c:11:8: note: expected ‘double’ but argument is of type ‘double (*)(double)’
homework5-3_template.c:48:2: error: too many arguments to function ‘get_root’
homework5-3_template.c:11:8: note: declared here
homework5-3_template.c: At top level:
homework5-3_template.c:52:37: error: parameter ‘a’ has just a forward declaration
homework5-3_template.c:52:24: error: parameter ‘pf’ has just a forward declaration
homework5-3_template.c: In function ‘get_root’:
homework5-3_template.c:58:7: error: ‘pf’ undeclared (first use in this function)
homework5-3_template.c:58:7: note: each undeclared identifier is reported only once for each function it appears in
homework5-3_template.c:58:11: error: ‘a’ undeclared (first use in this function)
#include
#include
#define ESP 0.001
#define F1(x) (x)*(x)*(x) + (x)*(x) + (x) + 7
#define F2(x) (x)*(x)*(x) + (x)*(x) + (x) - 8
#define F3(x) 3*(x)*(x)*(x) - (x)*(x) - 50*(x)
#define F4(x) 100*(x) +100
#define F5(x) -1*(x)*(x)*(x) - 70*(x)*(x) -5*(x) + 10
//parameter : function pointer, double v1, double v2
double get_root(double pf[]; double a; double b);
double func1(double x){
return F1(x);
}
double func2(double x){
return F2(x);
}
double func3(double x){
return F3(x);
}
double func4(double x){
return F4(x);
}
double func5(double x){
return F5(x);
}
double (*eq[5]) (double x) = {func1, func2, func3, func4, func5};
void main()
{
double a,b;
double r;
int se;
printf("\nselect equation(0~4): ");
scanf("%d", &se);
if(se > 4 || se < 0){
printf("bad input\n");
return;
}
printf("\nEnter the value of x0: ");
scanf("%lf",&a);
printf("\nEnter the value of x1: ");
scanf("%lf",&b);
printf("\n a b m f(a) f(b) f(m)");
r = get_root(eq[se], a, b);
printf("\nroot = %f\n", r);
}
double get_root(double pf[]; double a; double b)
{
float m;
int i = 1;
double fa,fb,fm,t;
fm=(*pf)(a);
for(;i>0;i++){
m=(a+b)/2;
fa = (*pf)(a); fb = (*pf)(b); fm = (*pf)(m);
printf("\n%2d. %f %f %f %lf %lf %lf", i, a,b,m,fa,fb,fm);
if (fm<0) a=m;
else if (fm<0.0005&&fm>-0.0005) i=0;
else b=m;
}
return m;
//FILL
아 죄송해요 이상한 착각을 했네요
아 죄송해요 이상한 착각을 했네요
double get_root(double pf[];
double get_root(double pf[]; double a; double b);
선언부에서
이렇게 선언하시고요.
호출부에서도 콜론을 콤마로 고치세요.
제가 찾은 오류 중에 하나고요. 또 다른 오류는 찾아보세요. 오류 행하고 메시지 잘 보세요.
본인 맞습니다.
인증샷
우헤헤헤... 로 대신합니다.
댓글 달기