Gamestudio Links
Zorro Links
Newest Posts
Camera always moves upwards?
by clonman. 11/13/25 14:04
brokerCommand PLOT_HLINE parameters
by M_D. 11/13/25 10:42
ZorroGPT
by TipmyPip. 11/10/25 11:04
Training with the R bridge does not work
by frutza. 11/05/25 00:46
Zorro 2.70
by opm. 10/24/25 03:44
Alpaca Plugin v1.4.0
by TipmyPip. 10/20/25 18:04
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
5 registered members (Grant, AndrewAMD, ozgur, Quad, TipmyPip), 29,980 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sheliepaley, Blueguy, blobplayintennis, someone2, NotEBspark
19177 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: 311
Netherlands
G
Grant Online OP
Senior Member
Grant  Online OP
Senior Member
G

Joined: Aug 2017
Posts: 311
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: 28,029
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,029
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: 311
Netherlands
G
Grant Online OP
Senior Member
Grant  Online OP
Senior Member
G

Joined: Aug 2017
Posts: 311
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: 28,029
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,029
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: 311
Netherlands
G
Grant Online OP
Senior Member
Grant  Online OP
Senior Member
G

Joined: Aug 2017
Posts: 311
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