I have found a peculiar problem with writing to a 2D array of type integer
I created an global array like this..
int g_seq[15][6];
and a single global dimension array like this
int g_cmds[70];
When I tried to copy some of the values in the 1D array into the 2D array the result was not consistent
(as in most of the values copied over fine but there was this one index where the data appeared to be corrupte every time. I expected to see value7 in this field but got 9 instead, every time.)
I tried many things to see what might be happening under the hood; everything I could think of to isolate this and finally had to conclude that 2D array of type integer is not always going to act like expected. I did not have time to do an long term analysis.
I ended up having to restructure my program to get around this. Created 1D arrays and restructured the program and it works just fine.
BTW Arduino is very immersive! Lots of rewarding experiences with this technology.
I just wanted to ask if anyone has had any similar issues with 2D arrays of type integer.
I have had no issue with 2D array of type char.
If there was such a problem, thousands of people would have experienced it and it would have been fixed. Always suspect your own code first. Please post all your code, using code tags to make it readable.
The problem is most probably that you have not understood how multidimensional arrays are laid out in memory. Your 2-d array is structured as an array of 15 arrays of 6 ints.
this means that if you have
int foo[2][3];
int bar[6];
and bar[] contains 1,2,3,4,5,6; and you simply use memcpy(foo, bar, sizeof(foo)) to plonk bar() on top of foo(), then the result will be:
Another possibility that you might be getting wrong is that if you use memcpy, the size is in bytes. ints are two bytes long. You perhaps aren't multiplying by sizeof(int) when you need to. For instance, memcpy(foo, bar, 6 * sizeof(int)). Or maybe you are making the converse error, and multiplying when you shouldn't.
Another possibility is that you are using strcpy() instead of memcpy(). In C, strings are terminated with a trailing '\0', and the srcpy() function respects this by stopping when it comes to the first zero byte.
It is simply not the case that 2d arrays of int don't act as expected. They act exactly as I (for one) expect them to.