samedi 7 mars 2015

For loop performs weird increment jumps


I have the following code, which is part of a larger program. Here N = 108 and NDIM = 3.



for(i=0; i<N; i++){
for(j=0; j<NDIM; j++){
r[i][j] = rn[i][j];
printf("The new element (%d, %d) is %lf\n", i,j, r[i][j]);
boxsize[i] = boxsizen[i];
}
}


Compiling and running the program gives a segmentation fault, which I have traced to the line



r[i][j] = rn[i][j];


The double for loop seems to behave fine until we get to the point where i should take the value 46, instead i jumps from 45 to 1074846117, which is obviously a problem. What could cause this problem?




Aucun commentaire:

Enregistrer un commentaire