2D array problem

Hello I'm getting a problem with my 2d array, I'm getting a 90 degree wrong angle from the 2d array for example when I try this code javascript:tx('this->matrix[1][0] = 2;') it should be
-1 2 -1 -1...
-1 -1 -1 -1...
-1 -1 -1 -1...
and so on but instead it turnes
-1 -1 -1 -1...
2 -1 -1 -1...
-1 -1 -1 -1...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
	--constructor
	this->array= new int*[cap];
	for (int i= 0; i< cap; i++)
	{
		this->array[i] = new int[cap];
	}
	reset();
	


.....reset()
{
	for (int i= 0; i< cap; i++)
	{
		for (int j= 0; j< cap; j++)
		{
			this->array[i][j] = -1;
		}
	}
}
......print()const
{
	for (int i = 0; i < cap; i++)
	{
		for (int j = 0; j <cap; j++)
		{
			cout << this->array[i][j]<<" ";
		}
		cout << endl;
	}
this->matrix[0][1] = 2;
}
Hmm. You write "matrix[1][0]", but on line 31 you write "matrix[0][1]". Confusing.


Lets see what your print() does. When i==0, you show values array[0][j] and an std::endl. That is one printed line (aka first row). Thus, the 'i' is the index of a row and the 'j' determines column.
Topic archived. No new replies allowed.