Problem with custom data types


hello all!

i trying code work using custom data types.
the types defined this:

code: [select]

typedef struct
{
 int top;
 int center;
 int bottom;
 int input;
 int type;
 int trim;
 int rates;
 int position;
} stick;


i create array:

code: [select]

stick sticks[4];


i try set contents of array using function

code: [select]

void set_sticks()
{
 for (int = 0; < 5; i++) {
   sticks[i].top = stick_limits[i][0];
   sticks[i].center = stick_limits[i][1];
   sticks[i].bottom = stick_limits[i][2];
   sticks[i].type = stick_types[i];
   sticks[i].input = stick_inputs[i];
   sticks[i].trim  = stick_trims[i];
   sticks[i].rates = stick_rates[i];
   sticks[i].position = 0;
 }
}


but when arduino crashes. :(

i can access item in array other point this:
code: [select]

sticks[0].top = 200;


or using in set_sticks() function.

does have idea why might not working? can't head around it.

you allocate space 4 sticks...

code: [select]
stick sticks[4];

but you're accessing 5 sticks...

code: [select]
 for (int = 0; < 5; i++) {

allocate more space (sticks[5]) or access fewer sticks (change condition "i < 4").


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Problem with custom data types


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums