关于c指针函数的问题
最近在学习c语言指针部分,用到指针函数,写了如下程序,运行有错误。但我明明觉得不错哇!望高手赐教!!#include <stdio.h>
void main()
{
double add(double,double); //declare add,sub,mul,div functions
double sub(double,double);
double mul(double,double);
double div(double,double);
double (*oper_fun[])(double,double)={add,sub,mul,div};
while(1)
{
double a,b,c;
printf("This is a simple calculator,it has 5 functions as follows!\n");
printf("1.add\t2.sub\t3.mul\t4.div\t");
printf("Please enter as such format:number number operation\n");
scanf("%f%f%d",&a,&b,&c);
printf("Result is:%f\n",oper_fun[ c - 1](a,b));
}
}
double add(double x,double y) //add function
{return x+y;}
double sub(double x,double y) //sub function
{return x-y;}
double mul(double x,double y) //mul function
{return x*y;}
double div(double x,double y) //div function
{return x/y;}