Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (EternallyCurious, howardR), 646 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
strf length-limitation #467640
08/18/17 14:15
08/18/17 14:15
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline OP
Member
Grant  Offline OP
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Greetings all,

I'm working on a script to create a data set for R which requires a lot of input variables. As a result, the total character length per record exceeds the 1000 characters limit from the strf function. Is there a workaround for this?

for better readability I'm limiting the length of my code, but it looks like this

Code:
for(i=0; i < 10; i++)
{
file_append(name,strf(
				"n%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,etc...",
DS, (DS + IH), (DS + IH - 10), (DS + IH - 20), (DS + IH - 30), (DS + IH - 40), (DS + IH - 50), (DS + IH - 60), (DS + IH - 70), (DS + IH - 80), (DS + IH - 90),etc...));

DS = DS - 1;
}



Thanks for any feedback!

Grant

Re: strf length-limitation [Re: Grant] #467645
08/18/17 16:38
08/18/17 16:38
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Use not strf, but the equivalent C function sprintf, with a string of the desired length that you allocated before with malloc.

Re: strf length-limitation [Re: jcl] #467670
08/20/17 16:49
08/20/17 16:49
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline OP
Member
Grant  Offline OP
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Thank you for your suggestion, JCL.

I'm not familiar yet with this sprintf function, so I had to look it up.

I've tried the following simplified code, but now it seems that there's a hard limit for the number of individual arguments from the sprintf function: 123 max. Is this correct?

Once I try to compile my script with more arguments, it results in syntax error with a reference to the sprintf function.

Code:
function run()
  {
  char buffer[2000];
  int DS = 1500;
  string name = "DataExport.csv";
	
  if(is(FIRSTRUN))
    for(i=0; i < 10; i++)
      {
      sprintf(buffer,"n%i,etc..", DS, etc..);
      file_append(name, buffer);	
      DS = DS - 1;
      }
  }


Last edited by Grant; 08/20/17 18:18.
Re: strf length-limitation [Re: Grant] #467676
08/21/17 10:01
08/21/17 10:01
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
I don't know if there's a hard limit, but 123 is an awfully high number of arguments to a function. It is quite possible that you went where mankind has never been before. At least I never heard of a C function called with 123 arguments. I believe my own maximum was 18 arguments. Beyond, all sorts of things can happen.

Re: strf length-limitation [Re: jcl] #467682
08/21/17 14:13
08/21/17 14:13
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline OP
Member
Grant  Offline OP
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
I was able to throw it in a for-loop. It's definitely not the fastest way, but I only need this routine during the initialization of the model.
Once again thanks for your input!

Grant



Code:
function run()
{
char buffer[2500];
int DS = 1500, i, i2, i3, IH = 60;	
	
if(is(FIRSTRUN))
  for(i=0; i < 10; i++)
    {
    i3 = sprintf(buffer, "n%i", DS);
    for (i2=0; i2 < 144; i2++)
      {
      i3 += sprintf(buffer + i3, "%s", ",");
      i3 += sprintf(buffer + i3, "%i", DS + IH - (10 * i2));
      }
    file_append(name, buffer);
    DS = DS - 1;
    }
}


Last edited by Grant; 08/21/17 14:21.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1