I\'m currently learning to call compiled C code in R. Yesterday I created a function for the infinite pi series that when run in R returns a length 1 numeric vector (pi), w
fibonacci
is declared to take two pointers as arguments, and it doesn't return anything. But in your else
block, you're trying to call it with a single integer argument and capture a return value from it.
Try something like this in your else
block:
int n1 = *n - 1;
int n2 = *n - 2;
int ans1;
int ans2;
fibonacci(&n1, &ans1);
fobonacci(&n2, &ans2);
*ans = ans1 + ans2;
Also, in your else if
block, that should be (*n == 0)
.