Hi, I am having some trouble getting a 3d array of pointers to link up with a linked list for each of the array elements.
the 3d array of pointers is declared like this:
Code:
struct particle *cell[MAXCELLS][MAXCELLS][MAXCELLS];
and there are linked lists declared like this:
Code:
struct particle { /* structure for particles */
double sw[3]; /* square well components */
double hs[3]; /* hard sphere components */
double u[3]; /* unit vector for rotations */
struct particle *link;
};
I want to get the array pointers 'cell[x][y][z]' to point to the first observed particle in a function next to main, something like this:
Code:
void generate_list(){
int i,j,k,l;
/* determine the number of cells to decompose the simulation box in each of x, y and z directions*/
int(cells_x) = floor(boxX/cell_size);
int(cells_y) = floor(boxY/cell_size);
int(cells_z) = floor(boxZ/cell_size);
/* initialise the array of pointers to NULL */
for (j=0;j<cells_x;j++){
for (k=0;k<cells_y;k++){
for (l=0;l<cells_z;l++){
cell[j][k][l] = NULL;
}
}
}
/* determine the cell size */
cell_size_x = boxX/cells_x;
cell_size_y = boxY/cells_y;
cell_size_z = boxZ/cells_z;
/* populate cells with pointers to the first observed particles in each cell */
for (i=0;i<N;i++){
/* find which cell particle i is in */
i_cell_x = (int)(array[i].sw[0]/cell_size_x);
i_cell_y = (int)(array[i].sw[1]/cell_size_y);
i_cell_z = (int)(array[i].sw[2]/cell_size_z);
/* check whether cell already points to a particle, if not: point to current particle, else edit the pointer of the occupying particle to the current particle */
if (cell[i_cell_x][i_cell_y][i_cell_z] == NULL){
cell[i_cell_x][i_cell_y][i_cell_z] = &(array[i]);
} else {
}
}
}
I am getting a pointer type cast error when I compile "assignment from incompatible pointer type", can someone help please?