E
erfan
hi, here is my code :
//learn a pointer points to functions
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
double Add(double x,double y) {return (x+y);}
double Sub(double x,double y) {return x-y;}
double Mul(double x,double y) {return x*y;}
double Div(double x,double y) {return x/y;}
//double Pow(double x,double y) {return pow(x,y);}
double (*functable[5])(double,double)={Add,Sub,Mul,Div,pow};
char *msgtable[5]={"Sum","Sub","Mul","Div","Pow"};
int main()
{
int i;
double x=0,y=0;
printf("input two numbers:\n");
if(scanf("%lf,%lf",&x,&y)!=2)
{
printf("wrong input!\n");
exit(1);
}
for(i=0;i<5;i++)
printf("%s:%f\n",msgtable,functable(x,y));
return 0;
}
-------------------
when i run this programe,gcc gave me an error,that is :/tmp/cc2ZP8T4.o:
(.data+0x10): undefined reference to `pow'
collect2: ld $BJV2s(B 1
what`s wrong, i want to use function of pow,and his header
<<math.h>>was include,however,
where is the key of the error?
have a nice day
//learn a pointer points to functions
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
double Add(double x,double y) {return (x+y);}
double Sub(double x,double y) {return x-y;}
double Mul(double x,double y) {return x*y;}
double Div(double x,double y) {return x/y;}
//double Pow(double x,double y) {return pow(x,y);}
double (*functable[5])(double,double)={Add,Sub,Mul,Div,pow};
char *msgtable[5]={"Sum","Sub","Mul","Div","Pow"};
int main()
{
int i;
double x=0,y=0;
printf("input two numbers:\n");
if(scanf("%lf,%lf",&x,&y)!=2)
{
printf("wrong input!\n");
exit(1);
}
for(i=0;i<5;i++)
printf("%s:%f\n",msgtable,functable(x,y));
return 0;
}
-------------------
when i run this programe,gcc gave me an error,that is :/tmp/cc2ZP8T4.o:
(.data+0x10): undefined reference to `pow'
collect2: ld $BJV2s(B 1
what`s wrong, i want to use function of pow,and his header
<<math.h>>was include,however,
where is the key of the error?
have a nice day