system
1
Hello,
I am trying to learn how to use an array to return several numbers at once from a user defined function.
I keep running into the following error message: invalid conversion from 'int*' to 'int'
Any ideas? Thanks!
void setup()
{
int oldArray[] = {
5, 6 };
int newArray[] = {
0, 0 };
newArray = plusOne(oldArray, 1);
}
void loop() {
}
int plusOne(int inputArray, int indices)
{
int outputArray[indices];
for (int i=0; i<=indices; i++)
{
outputArray_=inputArray*+1;_
_ }_
_ return outputArray;_
_}*_
system
2
I am trying to learn how to use an array to return several numbers at once from a user defined function.
Functions can return a single value. They can not return an array.
You can pass the array to store the results in to the function, though.
system
3
You can return an array if it embedded in a structure.
void setup()
{
int ret_val;
int oldArray[] = {
5, 6 };
int newArray[] = {
0, 0 };
ret_val = plusOne(oldArray, 1, newArray);
}
void loop() {
}
int plusOne(int *inputArray, int indices, int* outputArray)
{
for (int i=0; i<=indices; i++)
{
outputArray[i]=inputArray[i]+1;
}
return 1; //yeay... success...
}
This?
Working example, best if done as a sketch and a header file as follows.
/* ==============================================================================
* File - types.h
* ------------------------------------------------------------------------------
*/
/* ==============================================================================
* ------------------------------------------------------------------------------
*/
struct point_t
{
short x, y;
};
/* ==============================================================================
* File - test_sketch.pde
* ------------------------------------------------------------------------------
*/
/* ==============================================================================
* ------------------------------------------------------------------------------
*/
#include "types.h"
/* ==============================================================================
* ------------------------------------------------------------------------------
*/
point_t funct1()
{
point_t pt = { 4, 12 };
return pt;
}
void loop()
{}
void setup()
{
point_t pt = funct1();
short x = pt.x;
short y = pt.y;
}