Gamestudio Links
Zorro Links
Newest Posts
A simple game ...
by bbn1982. 06/18/24 10:42
Face player all the time ...
by bbn1982. 06/18/24 10:25
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, bbn1982, vicknick), 652 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 4 1 2 3 4
multidimensional arrays as function arguments #429343
09/11/13 15:02
09/11/13 15:02
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
I'm trying to use a multidimensional array (of pointers) as a function argument.
However, I always get a 'dimension of array'-error when using an array with more than one dimension.

here's a little example:

one dimension (works)
Code:
#include <acknex.h>

var vars[8];

void print_var(var *input_array, unsigned int index_x)
{
	var output_var = input_array[index_x];
	
	printf("array[%.0f] = %.0f", (double)index_x, (double)output_var);
}

void main()
{
	int i;
	for(i = 0; i < 8; i++)
	{
		vars[i] = random(100);
	}
	
	print_var(vars, 3);
}


exactly the same using two dimensions (doesn't work)
Code:
#include <acknex.h>

var vars[8][8];

void print_var(var *input_array, unsigned int index_x, unsigned int index_y)
{
	var output_var = input_array[index_x][index_y];
	
	printf("array[%.0f][%.0f] = %.0f", (double)index_x, (double)index_y, (double)output_var);
}

void main()
{
	int i;
	for(i = 0; i < 8; i++)
	{
		int j;
		for(j = 0; j < 8; i++)
		{
			vars[i][j] = random(100);
		}
	}
	
	print_var(vars, 3, 5);
}



Does anybody know a solution to this problem?


POTATO-MAN saves the day! - Random
Re: multidimensional arrays as function arguments [Re: Kartoffel] #429346
09/11/13 15:18
09/11/13 15:18
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Pointer to a pointer


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: multidimensional arrays as function arguments [Re: WretchedSid] #429347
09/11/13 15:25
09/11/13 15:25
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
var **input_array

Re: multidimensional arrays as function arguments [Re: WretchedSid] #429349
09/11/13 15:28
09/11/13 15:28
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Sorry, but could you please post a small example?

edit:
@Ch40zzC0d3r: if you mean changing this
void print_var(var *input_array, unsigned int index_x)
into this:
void print_var(var **input_array, unsigned int index_x)

I've tried that before, didn't work smirk


POTATO-MAN saves the day! - Random
Re: multidimensional arrays as function arguments [Re: Kartoffel] #429350
09/11/13 15:32
09/11/13 15:32
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline
Senior Member
NeoNeper  Offline
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Code:
void print_var(var input_array)
{

	
	var output_var = input_array;
	
	printf("%.0f", (double)output_var);
}



...

Code:
print_var(vars[0][0]);


Last edited by NeoNeper; 09/11/13 15:33.

Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: multidimensional arrays as function arguments [Re: NeoNeper] #429351
09/11/13 15:34
09/11/13 15:34
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline
Senior Member
NeoNeper  Offline
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
OR:
Code:
void print_var(var **input_array, int index_x, int index_y)
{
	var output_var = vars[index_x][index_y];
	
	printf("array[%.0f][%.0f] = %.0f", (double)index_x, (double)index_y, (double)output_var);
}



Code:
print_var(vars, 0, 2);



Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: multidimensional arrays as function arguments [Re: NeoNeper] #429352
09/11/13 15:34
09/11/13 15:34
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
NeoNeper: thanks, but that's not what I'm looking for.

The code I've posted should just show the problem I have.
Printing a var from an array is not exactly what I want to do.


POTATO-MAN saves the day! - Random
Re: multidimensional arrays as function arguments [Re: Kartoffel] #429358
09/11/13 18:45
09/11/13 18:45
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Can really nobody of those who are expirienced with this provide a simple example? smirk


POTATO-MAN saves the day! - Random
Re: multidimensional arrays as function arguments [Re: Kartoffel] #429365
09/11/13 19:20
09/11/13 19:20
Joined: Nov 2007
Posts: 318
Brasil, Paraná
NeoNeper Offline
Senior Member
NeoNeper  Offline
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Code:
#include <acknex.h>


var vars[8][8];

void print_var(var **input_array, unsigned int index_x, unsigned int index_y)
{
	var output_var = vars[index_x][index_y];
	
	printf("array[%.0f][%.0f] = %.0f", (double)index_x, (double)index_y, (double)output_var);
}

void main()
{
	
	
	int i;
	int j;
	
	for(i = 0; i <= 8; i++)
	for(j = 0; j <= 8; j++)
	{
		vars[i][j] = 100;
	}
	
	
	wait(1);
	
	print_var(vars, 8, 8);

}


Last edited by NeoNeper; 09/11/13 19:25.

Please! Use easy words to be translated. because my English is not very good! Grateful.
_______________________________________________________
Re: multidimensional arrays as function arguments [Re: NeoNeper] #429369
09/11/13 19:37
09/11/13 19:37
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Sorry if you misunderstood me but like I've said previously: this is not what I'm looking for.

in your example you're accessing the global array 'vars' in the function:
void print_var(var **input_array, unsigned int index_x, unsigned int index_y)
{
var output_var = vars[index_x][index_y];


however, I want to access it by using the array as a function argument.
void print_var(var **input_array, unsigned int index_x, unsigned int index_y)
{
var output_var = input_array[index_x][index_y];


POTATO-MAN saves the day! - Random
Page 1 of 4 1 2 3 4

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