Array of strings?

Posted By: panz

Array of strings? - 08/18/16 20:12

I was trying to define an array of strings to store a bunch of symbol names. I tried the following methods which should be valid in standard C, but I got syntax errors in Zorro:

const char *array[] = {"USDJPY", "EURUSD", "USDCAD"};

Or:
char **array = (char *[]){"USDJPY", "EURUSD", "USDCAD"};

Eventually I was able to work around using the following:
string symb;
while(symb = loop("USDJPY", "EURUSD", "USDCAD"))
{
...
}

But this is not ideal as I cannot reuse the array somewhere else.

Does anyone know in Zorro how I should properly initialize an array of strings? If necessary I can accept a method that requires dynamic memory allocation.

Thanks!!
Posted By: Grat

Re: Array of strings? - 08/19/16 19:00

I'm use this:

Code:
#define SYMBOLS "EUR/USD","USD/JPY","NZD/USD","GBP/JPY","AUD/USD","EUR/NZD","USD/CAD","AUD/NZD","USD/CHF","EUR/GBP" 
...
...
while(loop(SYMBOLS)){
...

Posted By: panz

Re: Array of strings? - 08/20/16 15:34

Thanks, looks better. :-)
Posted By: jcl

Re: Array of strings? - 08/22/16 08:25

For a bunch of symbol names, the "official" method is storing them all in an asset list, and use the "Assets" pointer for the loop.

assetList("MySymbols.csv");
....
while(asset(loop(Assets))) ...

This way you don't need to change the script when adding or removing assets.
© 2024 lite-C Forums