Printing out a double pointer 90DEG clockwise

Hey guys, sorry for posting another problem. I made a function and my console keeps crashing but I'm convinced I have the notation right. All I'm doing is outputting, not even allocating memory and it crashes.
I'm trying to rotate a square matrix by 90 degrees and I simply just rotated the i and j then made, i, start from the largest dimension.

e.g.


Input: 2x2 Matrix
1 2 
3 4 
apply rotation

3 1
..crashes here


Original Matrix function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
void Matrix::printMatrix()          
{
 //this is my ORIGINAL matrix that I print out the it works perfectly fine.    
	for (size_t i = 0; i < matrixrow; i++)
	{
		for (size_t j = 0; j < matrixcolumn; j++)
		{
			std::cout << *(*(dMatrixPtr + i) + j) << " ";
		}
		std::cout << " \n";
	}

} 


Rotated Matrix function:
1
2
3
4
5
6
7
8
9
10
11
void Matrix::rotateMatrix()
{
	for (size_t j = 0; j < matrixcolumn; j++)
	{
//still outputs by filling rows but now takes from bottom column then moves up and restarts by rows.
		for (size_t i = matrixrow-1; i >= 0; i--) 
		{
			std::cout << *(*(dMatrixPtr + i) + j) << " ";
		}
		std::cout << " \n";
	}
Last edited on
for (size_t i = matrixrow-1; i >= 0; i--)
i is unsigned, the condition is a tautology.
Wow it works! Thanks that was so quick and simple.

I didn't think such a small detail would even make a difference. I thought the loop would just break when it tries to go to negative, not crash the program.

Thanks a lot!
Topic archived. No new replies allowed.