double **coords_fluid = newdouble*[5000];
for (int i = 0; i < n_atoms_methane; i++)
{
coords_fluid[i] = newdouble[4];
}
int k=0;
for( int i = 0; i < n_atoms_methane; i++ )
{
for( int j = 0; j < 4; j++ )
{
k=k+1;
coords_fluid[k][0] = rand(0,1)+x_point[j]*15.0;
coords_fluid[k][1] = rand(0,1)+y_point[j]*15.0;
coords_fluid[k][2] = rand(0,1)+z_point[j]*15.0;
coords_fluid[k][3] = type_point[j];
}
}
The purpose of this loop is to create a coordinate system consisting of randomly generated coordinates inside these (x,y,z) points that have been input from the text file.
Now, the problem is that when I run the program I get an unhandled exception during the last loop I've shown here. I suspect it is something to do with array sizes but I'm a bit confused by this.
My guess is that you're trying to write past the end of the coords_fluid array. You're not given us enough information to know for sure, as we don't know what the value of n_atoms_methane is.
Your best bet is to use a debugger, or add some debugging output. That will give you an idea of the state of the loop when it crashes. In particular, you'll want to look at which element of coords_fluid is being written to when it crashes.
apparently, x_point, y_point, z_point and type_point all have a size of 5 (assuming that they are the arrays referenced in void coords. If so, why does the loop over j only iterate from 0-3?