I cant return array in c,i am quite new to C so i probably do some kind of funny mistake, here is the code:
#define MAXSIZE 100
int recievedNumbers[MAXSIZE];
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
recievedNumbers = getACOfNumber(256);
for (int i = 0; i < sizeof(recievedNumbers) / 8; i++) {
Serial.print(recievedNumbers[i]);
}
Serial.println();
}
int* getACOfNumber(int theNumber) {
bool done = false;
int i = 0;
int theArray[100];
while (!done) {
if (theNumber % 2 == 0) {
theNumber = theNumber / 2;
theArray[i] = 2;
} else if (theNumber % 3 == 0) {
theNumber = theNumber / 3;
theArray[i] = 3;
}
else if (theNumber % 5 == 0) {
theNumber = theNumber / 5;
theArray[i] = 5;
}
else if (theNumber % 7 == 0) {
theNumber = theNumber / 7;
theArray[i] = 7;
} else {
theArray[i] = theNumber;
done = true;
}
i++;
}
return theArray;
}
Error Message :
AC:10: error: incompatible types in assignment of 'int*' to 'int [100]'
exit status 1 incompatible types in assignment of 'int*' to 'int [100]'
theArrayexist.theArraydoesn't exist anymore once your function returns, so returning its address is pointless, You need a static, a global, dynamic allocation, or a caller-provided buffer. Choose.