hello, I'm trying to make a calculator and I'm struggling to make a function invoke the right function based on a function pointer (for practice)
I'm struggling to understand how to define a function pointer, and the syntax on how it should be implemented. Please see below the attempt I've made so far :
#include <stdio.h>
int add(int, int);
int sub(int, int);
int mul(int, int);
int (*getfunc())(char);
int main(void)
{
puts("\t\tCalculator\n\n");
return 0;
}
int add(int a, int b)
{
return a + b;
}
int sub(int a, int b)
{
return a - b;
}
int mul(int a, int b)
{
return a * b;
}
int (*getfunc())(char op)
{
switch(op)
{
case '+': return getfunc = add;
case '-': return getfunc = sub;
}
}
however the compiler never likes the syntax for the function implementation, can someone please point me in the right direction? Thanks