making a function that will update and array
hello all,
not familiar using arrays c
but want have function can pass in value , filled array , move every value on one, throw out last 1 , put new value in beginning.
i not understand whole * thing in c, have seen around, not sure if need function work properly.
this code returns following error:
not familiar using arrays c
but want have function can pass in value , filled array , move every value on one, throw out last 1 , put new value in beginning.
i not understand whole * thing in c, have seen around, not sure if need function work properly.
code: [select]
int brain_data[30]={82960, 21827, 39586, 34202, 47124, 69690, 9468, 47798, 6563, 47456, 42494, 66574, 92910, 19151, 23587, 155965, 45245, 33233, 23437, 22788, 168338, 4015, 20487, 44382, 8065, 85082, 5408, 147608, 109213, 109210};
int * addvalue(int number , int array[]){
for (int i=0; i<29; i++){
int array_val;
array_val=array[i];
array[i+1]=array_val;
}
array[0]=number;
return array;
}
void setup()
{
serial.begin(9600);
serial.println(addvalue(500, brain_data));
}
void loop(){
}
this code returns following error:
code: [select]
call of overloaded 'println(int*) ambiguous
hi.
i think problem here:
what trying there? inside print function adding value array, moving array values around , returning whole array (by way, line "return array" return?).
i think if want print values in array, better of doing like:
you either before or after adding new value, depending on array values want print.
as addvalue function, think starting "end" of array, like
because have defined array on beginning (global variable), think don't need return it. function update values, when make serial.print() (like above example) should printing latest values.
well, didn't test code, idea wanted demonstrate
i think problem here:
code: [select]
serial.println(addvalue(500, brain_data));
what trying there? inside print function adding value array, moving array values around , returning whole array (by way, line "return array" return?).
i think if want print values in array, better of doing like:
code: [select]
for (int i=0; i<=30; i++) {
serial.println(brain_data[i]);
}
you either before or after adding new value, depending on array values want print.
as addvalue function, think starting "end" of array, like
code: [select]
int addvalue(int number){
(int i=29; i>=1; i--){
brain_data[i] = brain_data[i-1];
}
brain_data[0] = number;
}
because have defined array on beginning (global variable), think don't need return it. function update values, when make serial.print() (like above example) should printing latest values.
well, didn't test code, idea wanted demonstrate
Arduino Forum > Using Arduino > Programming Questions > making a function that will update and array
arduino
Comments
Post a Comment