I have problem in getting wrong values in array of double.
Instead of getting the values that I’d like to have in “printf” after defining the array’s values one by one, I got 0 instead
const int M=20;
const int K=2;
typedef double polybasis[M][K+1][K+1];
polybasis Phik;
for(i=1; i <= M; i++){
for (j=1; j <= K+1; j++){
for (k=0; k <= K+1; k++) {a0[k]=0.0;}
a0[1]=1.000;
a1=0.000;
for (k=1; k <= K; k++){
it=ind[k];
for (l=1; l <= k+1; l++){
a2 = a0[l];
a0[l]= a1-(x[i][it])*a2;
a1=a2;
}
}
for (k=0; k <= K+1; k++) {ind[k]=0;}
for (m=0; m <= K+1; m++) {
Phik[i][j][m]=a0[m];
Phik[i][j][m]=tmp*Phik[i][j][m];
printf("Phi %i %i %i : %7.8f ; ao : %7.8f \n",i,j,m,Phik[i][j][m],a0[m]);
//This is where I define the values that I need
}
}
}
//But in the end of the iteration, I got 0 values instead for every Phik[_][_][3]
//except the last one: Phik[20][3][3], from this test
printf("phi : %7.8f; \n",Phik[20][2][0]);
printf("phi : %7.8f; \n",Phik[20][2][1]);
printf("phi : %7.8f; \n",Phik[20][2][2]);
printf("phi : %7.8f; \n",Phik[20][2][3]);
I’m still new to C++, so I don’t know anything about memory leaks. I know that it’s better to use pointer to avoid this, but I need to use typedef for further steps.
Thanks for your help 🙂
C++ array indices are zero-based. The index must always be less than the extent of the array. For example, your first three loops should probably be: