This is a minimal reproducable example of the problem. Having height and length as parameters (rather than calculate them) is deliberate.
typedef struct
{
int red;
} triple;
int main(void)
{
triple array[3][3] = {
{ {.red = 10}, {.red = 40}, {.red = 70}},
{ {.red = 110}, {.red = 120}, {.red = 130}},
{ {.red = 200}, {.red = 220}, {.red = 240}}
};
printarray(2, 2, array);
}
void printarray(int height, int length, triple array[][length])
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < length; j++)
{
printf("red score at array[%i][%i] = %i\n", i, j, array[i][j].red);
}
}
}
The output I get is:
red score at array[0][0] = 10
red score at array[0][1] = 40
red score at array[1][0] = 70
red score at array[1][1] = 110
But I would expect:
red score at array[0][0] = 10
red score at array[0][1] = 40
red score at array[1][0] = 110
red score at array[1][1] = 120
The indexing of the 2d array is clearly not working as I expect, but why?