I'm writing a program that flips a two dimensional array 90, 180, or 270 degrees based on what the user requests. I figured out the algorithm for rotating the array (which I thought would be the hard part), but I've run into a problem that I never thought I would have. The following code is the snippet that generates the original array based on the dimensions that the user specifies. Its going to be randomly generated, but for troubleshooting purposes, I just made the generated array constantly ascending from 0 to 8 and have been setting the dimensions to 3x3 every time I run it for now.
1: int array_side_length = 3;
2: int x = 0;
3: int y = 0;
4: int original_array[array_side_length][array_side_length];
5: int z = 0;
6:
7: for(x = 0; x < array_side_length; x++){
8: printf("\n");
9: for(y = 0; y < array_side_length; y++){
10: original_array[x][y] = z;
11: z++;
12: printf("%d ", original_array[0][0]);
13: }
14: }
When I change line 12 to read
printf("%d ", original_array[x][y]);
the block of code generates the following array, as expected:
0 1 2
3 4 5
6 7 8
BUT... when I change the parameters of "original_array" to "[0][0]", I get the following:
0 0 0
3 3 3
6 6 6
This is confusing to me, because I expected the code to return an array of all zeros. I'm not seeing where the value of "original_array[0][0]" is changing.