Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
7 registered members (clonman, TipmyPip, Niels, dBc, Ed_Love, 3run, 1 invisible), 18,869 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Unable to Store String in Array #488401
10/08/24 14:36
10/08/24 14:36
Joined: Apr 2023
Posts: 60
V
vicknick Offline OP
Junior Member
vicknick  Offline OP
Junior Member
V

Joined: Apr 2023
Posts: 60
I tried to store some strings in array. I searched the web and tried out different solutions, but Zorro keeps giving error.

Here is one of my method:
Code
#define MAX_CURRENCIES 5
#define MAX_STRING_LENGTH 50

char* InterestFiles[MAX_CURRENCIES] = {"History\\AUDinterestrate.t6","History\\EURinterestrate.t6", "History\\GBPinterestrate.t6","History\\USDinterestrate.t6","History\\JPYinterestrate.t6"};

function run() {
    BarPeriod = 1440;  // Set bar period to daily
    StartDate = 2021;
    EndDate = 2024;

    // Print interest rate file paths
    for (int i = 0; i < MAX_CURRENCIES; i++) {
        printf("\nInterest Rate File: %s", InterestFiles[i]);
    }
}


Zorro gives this error:
Code
Error in 'line 5: 
syntax error
< char* InterestFiles[MAX_CURRENCIES] = {"History\\AUDinterestrate.t6","History\\EURinterestrate.t6", "History\\GBPinterestrate.t6","History\\USDinterestrate.t6","History\\JPYinterestrate.t6"};
 >.


Here is another method I tried:
Code
#define MAX_CURRENCIES 5           
#define MAX_STRING_LENGTH 50       

char InterestFiles[MAX_CURRENCIES][MAX_STRING_LENGTH];  

void initializeStrings() {
    // Copy file paths into the InterestFiles array
    strcpy(InterestFiles[0], "History\\AUDinterestrate.t6");
    strcpy(InterestFiles[1], "History\\EURinterestrate.t6");
    strcpy(InterestFiles[2], "History\\GBPinterestrate.t6");
    strcpy(InterestFiles[3], "History\\USDinterestrate.t6");
    strcpy(InterestFiles[4], "History\\JPYinterestrate.t6");
}

function run() {
    BarPeriod = 1440;  // Set bar period to daily
    StartDate = 2021;
    EndDate = 2024;

    initializeStrings();

     // Print interest rate file paths
    for (int i = 0; i < MAX_CURRENCIES; i++) {
        printf("\nInterest Rate File: %s", InterestFiles[i]);
    }
}


Zorro gives this error:
Code
Error in 'line 11: 

strcpy(): Pointer expected
<     strcpy(InterestFiles[0], "History\\AUDinterestrate.t6");
 >.

Last edited by vicknick; 10/08/24 14:38.
Re: Unable to Store String in Array [Re: vicknick] #488402
10/08/24 22:02
10/08/24 22:02
Joined: Oct 2018
Posts: 98
7
7th_zorro Offline
Junior Member
7th_zorro  Offline
Junior Member
7

Joined: Oct 2018
Posts: 98
You can find dynamic arrays and strings on the Zorro homepage.

https://opserver.de/down/DynamicArray_release_20180623.zip

https://opserver.de/down/ss.zip

Re: Unable to Store String in Array [Re: vicknick] #488403
10/09/24 14:40
10/09/24 14:40
Joined: Feb 2017
Posts: 1,806
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,806
Chicago
The first attempt I believe is illegal in Lite C (initializing an array of strings in a one-liner).

The second, your first argument in strcpy is char, not char*. And you need to use 2D array notation correctly.

I can't remember if this is legal in Lite C, but something like this:
Code
strcpy(&InterestFiles[0][0], "History\\AUDinterestrate.t6");
strcpy(&InterestFiles[1][0], "History\\EURinterestrate.t6");
// and so on...
Also, no need to initialize after the INITRUN is complete.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1