# Thread: function, array, pointer problem

1. ## function, array, pointer problem

Hi people.

This code works fine when N=DIM, but for N!=DIM doens't. How can i fix that and why this happen

Code:
```#include <stdio.h>

void InitialValues(double *ptr_total_force,double *ptr_chain_r, double *ptr_chain_v, double sigma,const int N, const int DIM){

double randomaux;
for (int i=0;i<N;i++){
for (int d=0;d<DIM;d++){
// vector force
ptr_total_force[i*N+d]=0;
// vector positions and velocities
ptr_chain_r[i*N+d] = 0.0;
ptr_chain_v[i*N+d] = 0.0;
if (d==0){
randomaux = 0.001*i*d; //gsl_rng_uniform_pos(r1);
ptr_chain_r[i*N+d] = randomaux;
// vector velocities
randomaux = 0.5*(i-d);//(2*gsl_ran_gaussian(r2,sigma) - 1);
ptr_chain_v[i*N+d] = randomaux;
}
}
ptr_chain_r[i*N+0] += sigma*i;
printf("%f\t%f\n",ptr_chain_r[i*N+0],ptr_chain_v[i*N+0]);
}

}

int main(){
const int N=4;
const int DIM=4;
double total_force[N][DIM];
double total_force_old[N][DIM];
double chain_r[N][DIM];   // monomer positions
double chain_v[N][DIM];   // monomer velocities
double sigma = 1.0; // diametro

InitialValues(total_force[0],chain_r[0], chain_v[0],sigma, N, DIM);
printf("-------------\n");
for (int i=0;i<N;i++){
printf("%f\t%f\n",chain_r[i][0],chain_v[i][0]);
}

}```

OUTPUT examples
N=4, DIM=3
0.000000 0.000000
1.000000 0.500000
2.000000 1.000000
3.000000 1.500000
-------------
1.500000 0.000000
0.000000 0.000000
0.000000 0.000000
0.000000 0.000000

N=4, DIM=4
0.000000 0.000000
1.000000 0.500000
2.000000 1.000000
3.000000 1.500000
-------------
0.000000 0.000000
1.000000 0.500000
2.000000 1.000000
3.000000 1.500000