I'm trying to run a function that returns a pointer, but when I try to store the returned value into my main loop it's giving me an error.
I'm trying to use a pointer to pointer since the return value of the function is a pointer, or is that wrong?
#include <stdio.h>
#include <wiringPi.h>
int **ptr;
int **ptr1;
int* readfunc (int storage[33]){
storage[0] = digitalRead(D0)+48;
storage[1] = digitalRead(D1)+48;
storage[2] = digitalRead(D2)+48;
storage[3] = digitalRead(D3)+48;
storage[4] = digitalRead(D4)+48;
storage[5] = digitalRead(D5)+48;
storage[6] = digitalRead(D6)+48;
storage[7] = digitalRead(D7)+48;
return storage;
}
int* readfunc2 (int storage2[33]){
storage2[0] = digitalRead(D0)+48;
storage2[1] = digitalRead(D1)+48;
storage2[2] = digitalRead(D2)+48;
storage2[3] = digitalRead(D3)+48;
storage2[4] = digitalRead(D4)+48;
storage2[5] = digitalRead(D5)+48;
storage2[6] = digitalRead(D6)+48;
storage2[7] = digitalRead(D7)+48;
return storage2;
}
int main(){
ptr = &readfunc2;
ptr1 = &readfunc;
return 0;
}
The error its giving me is
assignment to ‘int **’ from incompatible pointer type ‘int * (*)(int *)’ [-Wincompatible-pointer-types]
44 | ptr = &readfunc2;
warning: assignment to ‘int **’ from incompatible pointer type ‘int * (*)(int *)’ [-Wincompatible-pointer-types]
45 | ptr1 = &readfunc;
ptr = &readfunc2;This is not how you call functions. You are taking the address of a function instead of calling it. If you want to call it, tryreadfunc2(arg);but you need to provide the argument declared in parameter list and the variable where you want to store the pointer, has wrong type.