very simple question - array

 

Hi all,

I'm trying to do a very simple function, but without success

this is the function:


double hold_trade[];


int start()

{

for( int i=0; i<10; i++)

{

hold_trade[i] = i;

Print(hold_trade[i]);

}

}



This function is printing 0, instead of 1,2,3,4,5,6

Any idea?


Thanks


 
for( int i=1; i<=10; i++)
 
Still printing 0
 
rodrigosm:
[...] This function is printing 0, instead of 1,2,3,4,5,6

Either declare the size of the array:

double hold_trade[10];

int start()
{
   for( int i=0; i<10; i++) {
      hold_trade[i] = i;
      Print(hold_trade[i]);
   }
}

Or re-size it using ArrayResize() before accessing cells that don't exist yet:

double hold_trade[];

int start()
{
   for( int i=0; i<10; i++) {
      ArrayResize(hold_trade,i+1);
      hold_trade[i] = i;
      Print(hold_trade[i]);
   }
}


And next time...


 
gordon:

Either declare the size of the array:

Or re-size it using ArrayResize() before accessing cells that don't exist yet:


And next time...



Thanks! Now it's working well!
Reason: