advideLong & script

Posted By: Grat

advideLong & script - 06/25/20 17:07

Hi,

I have one script where I generate rules
Code
scritp gen.c

function run()
{
  	assetList("Assets4");
        string cSymbol=strx(Asset,"/","");
	Script = strf("AlfaEE_%s",cSymbol);

     ...
        vL = adviseLong(PATTERN+FAST,0,
}


and in second - where I use rules from first (gen.c). But I cannot get, if second script use this rules or not
Code
script second.c
function run()
{
  	assetList("Assets4");
        string cSymbol=strx(Asset,"/","");
	Script = strf("AlfaEE_%s",cSymbol);


I change name the script to:
Script = "AlfaEE_error";

but I dont see any error and script second.c runnign without problem. But no open any order.



Posted By: AndrewAMD

Re: advideLong & script - 06/25/20 21:14

Never use Script = strf(), chances of failure are about 100%. Use a real char buffer instead.
Posted By: Grat

Re: advideLong & script - 06/26/20 05:40

Ok,

I have rules from GEN.c store in:
AlfaEE_GBPUSD_GBPUSD.c

Now, I run second script with this:
cSymbol=strx(Asset,"/",""); // GLOBAL var
string cPom=strf("AlfaEE_%s",cSymbol);
Script = cPom;
printf("\nUse script %s",Script);

and in the LOGFILE I don't any problem.

I change the this:
string cPom=strf("eeeAlfaEE_%s",cSymbol);
Script = cPom;

and also not get any problem in the log file.


Is a possible get any info, which rules load in the script?
Posted By: AndrewAMD

Re: advideLong & script - 06/26/20 13:21

You didn't do what I said to do. You did not create a char buffer. Take a look at this code and its output:
Code
void main(void){
	string a = strf("apple");
	string b = a;
	char c[20];
	strcpy(c,a);
	string d = c;
	printf("\na1: %s",a);
	printf("\nb1: %s",b);
	printf("\nc1: %s",c);
	printf("\nd1: %s",d);
	int i;
	for(i=0;i<100;i++){
		strf("banana%d",i);
	}
	printf("\na2: %s",a);//undefined behavior (bad)
	printf("\nb2: %s",b);//undefined behavior (bad)
	printf("\nc2: %s",c);//defined behavior (good)
	printf("\nd2: %s",d);//defined behavior (good)
}

/*output:
a1: apple
b1: apple
c1: apple
d1: apple
a2: banana99
b2: banana99
c2: apple
d2: apple
*/
Note that a and b were ruined, whereas c and d remained intact.

By the way, strx() also returns temporary pointers, so you can expect similar problems.
© 2024 lite-C Forums