my program tends to crash when i try to delete this array...heres the basic setup
EDIT: my program SOMETIMES crashes..it crashes sometimes..and sometimes it runs smoothly
very weird stuff!
what is wrong?
Code:
int ** f;
int solve( int n, int capacity)
{
//create array
const int rows = n;
const int cols = capacity;
f = new int*[rows];
for(int i = 0; i < rows; i++)
f[i] = new int[cols];
for(int j = 0; j < cols; j++)
for(int i = 0; i < rows; i++)
f[i][j] = 0;
//MORE CODE HERE
//time to delete array of array
for (int i = 0; i < rows; i++)
{
delete [] f[i]; //CRASHES
//f[i] = null;
}
delete [] f;
//f = null;
}
any ideas?