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.
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";
}
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.