I have a code which is compiled but it's giving bus error during execution, I could not understand the problem. Any help regarding this matter would be appreciated. Thanks. The code is like the following
#include <iostream>
using std::cout;
using std::cin;
using std::ios;
using std::cerr;
using std::endl;
using std::left;
using std::right;
#include <iomanip>
using std::setw;
using std::setprecision;
#include <fstream>
using std::ifstream;
using std::ofstream;
#include <cmath>
#include <cstdlib>
int main(int argc, char* argv[])
{
if (argc != 4) {
cout << "Argument List: xbox ybox zbox" << endl;
exit(1);
}
int coordination[n_particles];
for(i=0; i< n_particles; i++)
coordination[i] = 0.0;
while (1) {
n=0;
if (inputFile.eof() == 1){
//std::cout << "end of file, breaking from loop\n";
break; //test whether we have reached the end
}
inputFile >> n;
inputFile.getline(tmp,200);
counter++;
if (counter==1) { //assumes the particle number is not changing
xx = new float[n]; //now we know the size
yy = new float[n];
zz = new float[n];
}
for (i=0;i<n;i++) { //loop over n atoms
inputFile >> atype >> xx[i] >> yy[i] >> zz[i];
}
for (i=0;i<(n-1);i++) {
for (j=i+1;j<n;j++) {
dx = xx[i] - xx[j];
dy = yy[i] - yy[j];
dz = zz[i] - zz[j];
// invoke minimum image convention
if (dx > xbox/2.0) dx = dx - xbox;
if (dx < -1.0*xbox/2.0) dx = dx + xbox;
if (dy > ybox/2.0) dy = dy - ybox;
if (dy < -1.0*ybox/2.0) dy = dy + ybox;
if (dz > zbox/2.0) dz = dz - zbox;
if (dz < -1.0*zbox/2.0) dz = dz + zbox;