Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (monarch), 1,259 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
multi dimensional array as function parameter #237043
11/17/08 19:16
11/17/08 19:16
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
Is it possible to use a multi dimensional array as a function parameter ???

For example:

STRING* mdArray[10][3];

and then something like that:

void testFunction(STRING* param[][]);

Best regards,
Pegamode.

Re: multi dimensional array as function parameter [Re: pegamode] #237052
11/17/08 19:40
11/17/08 19:40
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Yes it is. My personal guess would be, that you have to write STRING*** in the parameter declaration, but it is expected to work.


Always learn from history, to be sure you make the same mistakes again...
Re: multi dimensional array as function parameter [Re: Uhrwerk] #237054
11/17/08 19:45
11/17/08 19:45
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
It's not working ...

void testFunction(STRING*** param) {
diag(param[0][0]);
}

gives me a "dimension of array error".

Re: multi dimensional array as function parameter [Re: pegamode] #237055
11/17/08 19:46
11/17/08 19:46
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Have you tried you version?


Always learn from history, to be sure you make the same mistakes again...
Re: multi dimensional array as function parameter [Re: Uhrwerk] #237057
11/17/08 19:59
11/17/08 19:59
Joined: Feb 2006
Posts: 1,011
Germany
pegamode Offline OP
Serious User
pegamode  Offline OP
Serious User

Joined: Feb 2006
Posts: 1,011
Germany
yes, I did ... always "dimension of array error" or "syntax error".

Re: multi dimensional array as function parameter [Re: pegamode] #237058
11/17/08 20:11
11/17/08 20:11
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I guess you then need to do some pointer arithmetics. That's not nice, but works reliably. But maybe other have additional better ideas?


Always learn from history, to be sure you make the same mistakes again...
Re: multi dimensional array as function parameter [Re: Uhrwerk] #237153
11/18/08 17:37
11/18/08 17:37
Joined: May 2006
Posts: 53
Puerto Rico
monchito Offline
Junior Member
monchito  Offline
Junior Member

Joined: May 2006
Posts: 53
Puerto Rico
Hi... A7.5 Comm.
Maybe something like this could help you or any one
who want to try... smile
Code:
[/code]

#include <acknex.h>
#include <default.c>

var video_depth = 32;
  
STRING* mdArray[10];

void testFunction(STRING** param)
{
  diag(param[0]);
  diag(param[1]);
  diag(param[2]);
}

function main()
{
   level_load(NULL);
   STRING* A0 = "\nline 0";
   STRING* A1 = "\nline 1";
   STRING* A2 = "\nline 2";
   mdArray[0] = A0;
   mdArray[1] = A1;
   mdArray[2] = A2;

  // str_cpy(mdArray[0], "\nreplace string data mdArray[0]");
  // str_cpy(mdArray[1], "\nreplace string data in mdArray[1]");

   testFunction(mdArray);

}

[code]


Re: multi dimensional array as function parameter [Re: monchito] #237234
11/19/08 05:52
11/19/08 05:52
Joined: Aug 2003
Posts: 902
Van Buren, Ar
Gordon Offline
User
Gordon  Offline
User

Joined: Aug 2003
Posts: 902
Van Buren, Ar
If the above code works (did not test) then you can do multi dim arrays by index = index_x + index_Y * size_index_x; . if this is not the case try swaping x and y in the above statement. if this is still not right then LC is using some funky array indexing. This works for standard C and C++ if you know the size of the first index. It is implementation specific and may change without notice.


Our new web site:Westmarch Studios
Re: multi dimensional array as function parameter [Re: Gordon] #237262
11/19/08 10:35
11/19/08 10:35
Joined: May 2006
Posts: 53
Puerto Rico
monchito Offline
Junior Member
monchito  Offline
Junior Member

Joined: May 2006
Posts: 53
Puerto Rico
Hi
Maybe accessing in a different way.
Code:
[/code] 
#include <acknex.h>
#include <default.c>
#define ROWS    10
#define COLUMS   3

var video_depth = 32;
  
STRING* mdArray[30]; // ROWS * COLUMS;

void testFunction(STRING** param)
{
  diag(param[0]);
  diag(param[1]);
  diag(param[2]);
}

void testFunction2(STRING** param, int x, int y)
{
  diag(param[x * COLUMS + y]);   // x + COLUMS * y
}

function main()
{
   level_load(NULL);
   //STRING* A0 = "\nline 0";
   STRING* A1 = "\nline 1";
   STRING* A2 = "\nline 2";
   STRING* A29 = "\narray last item";
   mdArray[0] = (STRING*)malloc(sizeof(STRING)); // allocate memory
 //mdArray[0] = A0;
   mdArray[1] = A1;
   mdArray[2] = A2;
   mdArray[29] = A29;

  // str_cpy(mdArray[0], "\nreplace string data mdArray[0]");
  // str_cpy(mdArray[1], "\nreplace string data in mdArray[1]");
   
   //for malloc use this
   strcpy((mdArray[0]).chars, "\nreplace string data mdArray[0]");
   
   testFunction(mdArray);
   
   testFunction2(mdArray, 0, 0);
   testFunction2(mdArray, 9, 2);

}
[code]



Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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