return an array from a function
i want return array function. follow error :
in function 'int getrgb()':
error: invalid conversion 'int*' 'int' in function 'void loop()':
writing : int getrgb()[3] doesn't seem work :
error: 'getrgb' declared function returning array in function 'int getrgb()':
i searched in forum couldn't find syntax it.
code example :
in function 'int getrgb()':
error: invalid conversion 'int*' 'int' in function 'void loop()':
writing : int getrgb()[3] doesn't seem work :
error: 'getrgb' declared function returning array in function 'int getrgb()':
i searched in forum couldn't find syntax it.
code example :
code: [select]
int colorsrgb[3];
int colors_1[3];
int colors_2[3];
int getrgb()
{ colorsrgb[0]=255;
colorsrgb[1]=0;
colorsrgb[2]=0;
return colorsrgb;
}
colors_1=getrgb();
colors_2=getrgb();
you're getting relatively tricky area, touching on pointers, memory management, etc. the easiest solution pass array function , write result (rather trying return array). that is:
code: [select]
int colors1[3];
void getrgb(int colors[3])
{
colors[0] = 255;
colors[1] = 0;
colors[2] = 0;
}
void loop()
{
getrgb(colors1);
}
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > return an array from a function
arduino
Comments
Post a Comment