I have been running this random walk simulation for a while now and I keep getting an error EXC_BAD_ACCESS from Xcode. Its printing out a large part of the simulation though.
I think its running out of memory for some reason but I am not sure why.
If I go towards the end of the array I edited it so I don’t get within 100 spaces of the edge (by editing the variable steps to steps -100). This works but I would like to know whats going on.
Any help would be appreciated.
double** places;
places = (double**) malloc(steps*sizeof(double*));
for (int i = 0; i < steps; i++)places[i] = (double*) malloc(2*sizeof(double));
for (i = 0; i< steps/*, exit*/; i++) {
// Find the angle of movement
angle = getRand()*360;
// Take a step
xPos+= STEP*cos(angle);
yPos+= STEP*sin(angle);
//Write Step to array
places[i][1] = xPos;
places[i][2] = yPos;
//Write Step to File
fprintf(ff, "%d %lf %lf\n",i,xPos,yPos);
}
Array indexes start at zero.
Did you mean to write this?