Zero at end of pointer!
Aug 16, 2011 at 1:34am UTC
Hi,
I am having a problem with a pointer.
My pointer pn_eles[nTotNodes][nNode] is properly initialized filled with integer values, so that when I run this fragment:
1 2 3 4 5 6 7 8 9 10 11
for (int iii=0; iii<nEles; iii++)
{
inEl >> pn_elNum[iii];
for (int jjj=0; jjj<nNode; jjj++)
{
inEl >> pn_eles[iii][jjj];
cout << pn_eles[iii][jjj] << "\t" ;
}
cout << endl;
}
I get the following output:
1 2 5 4
2 3 6 5
4 5 8 7
5 6 9 8
7 8 11 10
8 9 12 11
But when I run this fragment:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
for (int elcount=0; elcount<nEles; elcount++)
{
cout << "elcount = " << elcount << endl;
for (int iii=0; iii<nDim; iii++)
{
for (int jjj=0; jjj<nDim; jjj++)
{
aj[iii][jjj]=0;
for (int kkk=0; kkk<nShape; kkk++)
{
aj[iii][jjj]+=NN_deriv[kkk][iii]*pd_nodes[pn_eles[elcount][kkk]][jjj];
} //endfor
cout << aj[iii][jjj] << "\t" ;
} // endfor
cout << endl;
} //endfor
cout << "\n \n" ;
} //endfor
I get a bus error when elcount is 5:
elcount = 5
Bus error
Through print statements, I discovered that the error is caused by pn_eles[5][3], which should be 11, is giving me:
11
0
How do I get rid of this zero at the end of my pointer array?
I'm not sure if I explained this well, please let me know if I need to clarify.
Thanks!
Aug 16, 2011 at 2:50am UTC
I don't understand. ¿how is giving you two values?
You said that the array was pn_eles[nTotNodes][nNode]
,
however you are trying to access till pn_eles[nTotNodes-1][nShape-1]
¿Is that a valid range?
Aug 18, 2011 at 8:39pm UTC
I figured it out! There was a problem with something completely different that was causing the bus error.
Topic archived. No new replies allowed.