2 registered members (AndrewAMD, VoroneTZ),
919
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Expert
|
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: pegamode]
#237055
11/17/08 19:46
11/17/08 19:46
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
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: pegamode]
#237058
11/17/08 20:11
11/17/08 20:11
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
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
Junior Member
|
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... [/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: Gordon]
#237262
11/19/08 10:35
11/19/08 10:35
|
Joined: May 2006
Posts: 53 Puerto Rico
monchito
Junior Member
|
Junior Member
Joined: May 2006
Posts: 53
Puerto Rico
|
Hi Maybe accessing in a different way. [/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]
|
|
|
|