Hi
I would like to add 1 to a single element of a 2 dimensional array, for example if the declared array is:
uint8_t array1 [2][2] = {{1,2},{3,4}};
and at some point in the main loop I want to add 1 to element [2][2]. How do I do it?
I have tried:
array1 [2][2] = array1 [2][2]+1;
array1 [2][2] = {array1 [2][2]+1};
array1 [2][2] = {{array1 [2][2]}+1};
array1 [2][2] = {(array1 [2][2])+1};
Thanks
system
February 19, 2017, 8:03pm
2
array1 [2][2] =
A two element array doesn't have 2 as a valid subscript.
To add one to elements
array1 [0][0]++;
array1 [0][1]++;
array1 [1][0]++;
array1 [1][1]++;
Hi Sorry I just reread the question and as always I made some mistakes
2 dimensional array as in
uint8_t array1 [2][2] = {{1,2},{3,4}};
and adding one to element [2][2], so as to become:
uint8_t array1 [2][2] = {{1,2},{3,5}};
Understand what I mean?
Cheers
D
Hi,
I've tried it but.... it doesn't work
//uint8_t decimal_X [21] [2]; // This is how the array is defined
//uint8_t decimal_Y [21] [2];
decimal_X[0][0] = {1+1};
decimal_Y[0][0] = {9};
Serial.print("X&Y:\t");
Serial.print(decimal_X[0][0]);
Serial.print("\t");
Serial.println(decimal_Y[0][0]);
decimal_X[0][0]++;
decimal_Y[0][0]++;
and here is the output I get in attachment
system
February 19, 2017, 8:30pm
6
it doesn't work
Lamest comment . . . ever.
The code you posted doesn't / cannot compile, so cannot "work".
If you want help, be specific.
system
February 19, 2017, 8:36pm
7
You didn't think your "report to moderator" through, did you?
I'm the fat guy off the Simpsons.
Its from a larger section of code
uint8_t decimal_X [21] [2];
uint8_t decimal_Y [21] [2];
void setup() {
Serial.begin(115200);
while (!Serial);
}
void loop() {
decimal_X[0][0] = {1+1};
decimal_Y[0][0] = {9};
Serial.print("X&Y:\t");
Serial.print(decimal_X[0][0]);
Serial.print("\t");
Serial.println(decimal_Y[0][0]);
decimal_X[0][0]++;
decimal_Y[0][0]++;
}
system
February 19, 2017, 8:42pm
9
OK, so what's your definition of "this code works"?
(please bear in mind the fact that you overwrite the values you just incremented each time through loop() )
Ow dear :o .... oops ;/ ouch .... cheery o fat guy from Simpsons