Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AbrahamR, 1 invisible), 858 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
String interpolation crashing Zorro #456206
11/14/15 18:22
11/14/15 18:22
Joined: Jul 2015
Posts: 2
N
neosb Offline OP
Guest
neosb  Offline OP
Guest
N

Joined: Jul 2015
Posts: 2
Hey, I have a code like this:

Code:
action = "";
strcat(action, "Strategy/ghost.py ");
strcat(action, strf("'%s' ", Asset));
strcat(action, strf("%d ", Money));
strcat(action, strf("%d ", ExitTime));
strcat(action, "'90% / 0%' ");
strcat(action, "'put'");
printf("\nCreated action...");
exec(action_file, action, 1);
printf("\n%s\n\n", action);
Sleep(33);



This is a part of a function that is called when the trade is executed. Unfortunately it's failing with a crash in script and inconsistent series calls, sometimes in other configurations it gives a trade in one direction but I'm never able to repeat a trade in that direction with another crash in script. Please tell me how should I create a string that is recreated every time I place a trade.

There is no problem with exec function, it's called properly, the output of current stage is failing and printing my string, but not "Created action...". I'm not good with C, I've always worked on higher-level languages starting with C++ and I'm not clearly sure how to go about this string interpolation...

What is strange, is that this code works well when the function is called just once, like you would make a separate program with just that code and a global string action, but this is not the case.

Last edited by neosb; 11/14/15 18:59. Reason: additional info about issue with string interpolation
Re: String interpolation crashing Zorro [Re: neosb] #456211
11/15/15 09:25
11/15/15 09:25
Joined: Apr 2008
Posts: 586
Austria
Petra Offline
Support
Petra  Offline
Support

Joined: Apr 2008
Posts: 586
Austria
Look here:

action = "";
strcat(action, "Strategy/ghost.py ");

strcat will not make a string longer, it will crash when that happens because you're wrinting randomly into memory and this way overwrite maybe pointers and variables.

It would work when you have an enough long string, like

char action[1000]

Ohterwise better use strf for making a string, this makes your code much shorter, and strcat is anyway an old and outdated C function.



Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1