I have a two dimensional array of ints which represents a few dots in a graph.
int16_t myPoints[][3] = {
{0, 0},
{20, 40},
{14, 92}};
How can I pass a pointer to a function which will be able to read these coordinates?
something like?
void foo(int16_t *coordinates[][]) {
drawPoint(x[0], y[0]);
drawPoint(x[1], y[1]);
...
Thanks for the help.
Only the first dimension can be unknown when declaring a function, so you have to declare/define the function like this:
Then you can call it like a normal function:
Edit: Your array declaration is not correct, and I missed it too. It should be:
Now you have a proper coordinate-array, and it can be as long as you like.
For the function to know the number of entries, you have to pass it to the function, so the new function declaration will be:
Don’t worry about copying, the compiler is smart enough to only pass the pointer to the array, so it will not copy the whole array.