C programming: Exc bad access - struct array.

Feb 6, 2012 at 12:11pm
Hello

I am stuck with this latest problem, hope someone can help me. Thank you very much in advance.

=== CODE STARTS ===
struct nodes {
int numberStored;
struct nodes *left;
struct nodes *right;
} numbers[10];


for (i=0; i < 10; i++)
{
theFunction(numbers[i].numberStored,numbers[i+1].numberStored,&numbers);
}

void theFunction(int top,int bottom,struct nodes *numbersF[])
{
(*numbersF[0]).numberStored = 20; /// <<<< ERROR HERE!
}
=== CODE ENDS ===

This is where I get exc bad access. I am not certain what the problem is, hope someone can help.

Thanks
cnewey
Feb 6, 2012 at 12:23pm
Try

theFunction(numbers[i].numberStored,numbers[i+1].numberStored,numbers);
Feb 6, 2012 at 12:29pm
You are accessing the array out of bounds. (last iteration of the loop)
Also there is no need for the extra level of indirection. http://www.cplusplus.com/doc/tutorial/arrays/ (arrays as parameters)

Side note: It should be an easier way for posting code. Especially considering that this is a programming forum.
Feb 6, 2012 at 7:38pm
Thank you Moschops and ne555
Topic archived. No new replies allowed.