Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 05:41
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, AndrewAMD), 1,278 guests, and 2 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
opening files #422848
05/18/13 14:57
05/18/13 14:57
Joined: Nov 2012
Posts: 126
B
blaub4r Offline OP
Member
blaub4r  Offline OP
Member
B

Joined: Nov 2012
Posts: 126
I tried to open a file in a Zorro script using this code:

// -----------------------------------
#include <stdio.h>
bool schalter1 = false;
bool schalter2 = false;
FILE *pf;

function run()
{
if (!schalter1)
{
schalter1 = true;
pf = fopen("D:\Zorro\Log\test.txt","w");
}

var *Price = series(price());
var *Trend = series(LowPass(Price,1000));
var *Signals = series(0);

Stop = 4*ATR(100);
if (year(0) == 2013 && !schalter2)
{
msg("%f",pf);
schalter2 = true;
fprintf("Hallo",pf);
fclose(pf);
}
}
// -----------------------------------------

But it does not work as 0 is assigned to pf which means there was an error while opening the file.
Can someone help me with that?

Re: opening files [Re: blaub4r] #422849
05/18/13 15:26
05/18/13 15:26
Joined: May 2013
Posts: 23
Somewhere
W
Wiseguy Offline
Newbie
Wiseguy  Offline
Newbie
W

Joined: May 2013
Posts: 23
Somewhere
You need to escape the '\' character. The correct path would be "D:\\Zorro\\Log\\test.txt". Also make sure that you have write access to the path.


His words are wise, his face is beard.
Re: opening files [Re: Wiseguy] #422850
05/18/13 16:28
05/18/13 16:28
Joined: Nov 2012
Posts: 126
B
blaub4r Offline OP
Member
blaub4r  Offline OP
Member
B

Joined: Nov 2012
Posts: 126
Ok, thanks, this seemed to be part of the problem. Now the file is created but it remains empty.
And I think I do have write access as Zorro writes his own logs there, too.

Re: opening files [Re: blaub4r] #422860
05/19/13 01:01
05/19/13 01:01
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
change this line pf = fopen("D:\Zorro\Log\test.txt","w"); by this

pf = fopen("D:/Zorro/Log/test.txt","w");

Re: opening files [Re: Dico] #422871
05/19/13 08:09
05/19/13 08:09
Joined: May 2013
Posts: 23
Somewhere
W
Wiseguy Offline
Newbie
Wiseguy  Offline
Newbie
W

Joined: May 2013
Posts: 23
Somewhere
@Dico: While the underlying API to resolve filenames does support Unix style file separators, it's not recommended to use them.

@blaub4r: Check the declaration of the fprintf() function, especially the signature wink


His words are wise, his face is beard.
Re: opening files [Re: Wiseguy] #422874
05/19/13 09:50
05/19/13 09:50
Joined: Nov 2012
Posts: 126
B
blaub4r Offline OP
Member
blaub4r  Offline OP
Member
B

Joined: Nov 2012
Posts: 126
Originally Posted By: Wiseguy

@blaub4r: Check the declaration of the fprintf() function, especially the signature wink

Thank you, I got it now laugh


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1