I am trying to use a function as a parameter for another function. I want to get different computations depending on the function I pass. I tried implementing this by writing this program:
http://pastebin.com/CJfFarVa
Code:
The problem is I get this error over and over again:
trapeze.c:14:8: error: conflicting types for ‘exp2’
double exp2(int number);
trapeze.c: In function ‘main’:
trapeze.c:28:35: error: expected expression before ‘int’
exp_2 = trapeze(0, 1, n, exp2(int x));
^
trapeze.c:29:35: error: expected expression before ‘int’
exp_1 = trapeze(0, 1, n, exp1(int x));
^
trapeze.c: At top level:
trapeze.c:58:8: error: conflicting types for ‘exp2’
double exp2(int number)
Note: I do not want to use pointers to functions.
Sorry if this is an easy question.
Change the call to trapeze:
exp_2 = trapeze(0, 1, n, exp2);
exp_1 = trapeze(0, 1, n, exp1);
C is not a functional programming language, which means function is not a first-class object, therefore, you cannot pass function as argument of other functions, you have to use pointer to function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With