I use cout<<"something"; to find a location as to where the program is crashing. However, they don't print even though the debugger says the program crashes at a line after the cout<<"something";
Code:
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
void crossProduct (int **matrixA, int am, int an, int **matrixB, int bm, int bn, int **matrixC) {
int x= 0;
cout<<"something2";
int temp;
for (int i = 0; i<am; i++)
for (int j = 0;j<an; i++) {
for (int k =0;k<bm;k++)
for (int l=0;l<bn;l++) {
cout<<"x:"<<x<<" ";
x++;
temp = matrixB[k][l] * matrixA[i][j] + temp;
}
matrixC[i][j] = temp;
temp = 0;
}
}
int main() {
int **p1, **p2, **p3;
int i;
int sizeX =3;
int sizeY =3;
p1 = new int*[sizeX];
p2 = new int*[sizeX];
p3 = new int*[sizeX];
for (i = 0; i < sizeX; ++i) {
p1[i] = new int[sizeY];
p2[i] = new int[sizeY];
p3[i] = new int[sizeY];
}
//////////////////////////////////////////////////////
initMatrix(p1,sizeX, sizeY);
initMatrix(p2,sizeX,sizeY);
printMatrix(p1,sizeX,sizeY);
printMatrix(p2,sizeX,sizeY);
cout<<"something1";
crossProduct(p1,sizeX,sizeY,p2,sizeX,sizeY,p3);
printMatrix(p3,sizeX,sizeY);
...something down here...
Where initMatrix fills it with values, and printMatrix does exactly that.
The debugger is telling me that the program crashes at:
Code:
temp = matrixB[k][l] * matrixA[i][j] + temp;
However, something1 and something2 don't print. If I comment out
Code:
// crossProduct(p1,sizeX,sizeY,p2,sizeX,sizeY,p3);
like so, the program runs and doesn't crash.
This is very strange...