Hi im trying to get some code to work and i keep getting
First-chance exception at 0x00f32d34 in prog.exe: 0xC0000005: Access violation reading location 0x333f8630.
Unhandled exception at 0x00f32d34 in prog.exe: 0xC0000005: Access violation reading location 0x333f8630. |
What i want is a 2d dynamic array/matrix of size [b by b].
This array is used to check if an event will happen, I require it first to be filled with 0's then filled with ones along the diagonal e.g.
1000
0100
0010
0001
This array/matrix has to be used and cleaned meny times so im trying to make a function that would do this so i dont have to have the same lines over and over. so far ive got this.
The function that should input the diagonal
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
|
inline int** matrixrefresh(int**& a, int& b)
{
int i;
// declaration
int ** c;
// allocation
c = new int*[b];
for(int i = 0; i < b; i++)
c[i] = new int[b];
// initialization
for(int j = 0; j < b; j++)
for(int i = 0; i < b; i++)
c[i][j] = 0;
while(i < b)
{
c[i][i] = 1;
i++;
}
a = c;
return a;
}
|
Then Mid way through int main the matrix I'm going to use is made and initialised
1 2 3 4 5 6 7 8 9 10 11 12
|
// declaration
int ** checkingmatrix;
// allocation
checkingmatrix = new int*[b];
for(int i = 0; i < b; i++)
checkingmatrix[i] = new int[b];
// initialization
for(int j = 0; j < b; j++)
for(int i = 0; i < b; i++)
checkingmatrix[i][j] = 0;
|
Then i call the function to input the diagonal
matrixrefresh(checkingmatrix,b);
Then finaly leter on inside a few while loops its used for checking
1 2 3 4
|
if (checkingmatrix[a][b] = 0)
{
stuff
}
|
It compiles and works fine untill this part of the function. [the c[i][i] line to be exact]
1 2 3 4 5
|
while(i < b)
{
c[i][i] = 1;
i++;
}
|
Any help would be greatly appreciated. Also just to note I don't know to much about c++ most of this code has been grabbed of various forum posts around the net and cobbled together.