Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Multiple dimesion arrays question !!!

This topic is 6075 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

if i declare this int map[3][10][10]; if i want to initialize it would it be some like this ? int map[3][10][10] = {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0}; is this mostly used in little games maps ? like to load a maps and make the colors of it base on the numbers on the array ? "The shortcut is not always the best way " ][v][etal ''][''yphoon

Share this post


Link to post
Share on other sites
Advertisement
That looks like alot more typing than I would ever recomend. There
are much better ways of zeroing everything if needed. Even if you
just do a simple loop thing you could spare you fingers alot of
pain and suffering. Especialy if you want anything bigger than
[3][10][10] map.
At int map[x][x][x];
you already have your map array ready to recive any value you want
zero or otherwize. I have a question. Does your plan require you
to restrict your map to a set size. If you declare the size at the
start you are limmited to that size for your entire program.
I''m sorry someone will need to clean up after what I''m sain I
reeeeal rustly and just starting to program agian but I have made
a tile engine before(I''m asumming that the map[][][] is for such
a thing.)
You can declare your map as an undefined size by leaving the
[] empty. It may not be that qutie that simple.
I think my compiler forced me to define at least one dimention
of the array at starup. I belive what I did was declare the
array as a one dimentional array and then after I knew what size
i needed I filled it with function like malloc. After I had a
spot in memory I started addressing the array like it was a multi
dimential array. I''m so out of it right now I cant recal all
of the details but I know someone here can easly help you
sort the details out if you want. That way your not nailed down
by any one size map. Hope I understood your need otherwize
Ive rambled like a crazed idiot for no good reason. Ahh
who need a good reason for that anyway.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
wHAZ uP ???

Zeroing Out every Array at Runtime......

void main()
{
unsigned char Field[3][10][10];
memset((void *)&Field,0,3*10*10);
}
or a other way;

void main()
{
unsigned cahr Field[3][10][10];
unsigned char i,j,k;
for(i=0i;<3;i++)
for(j=0;j<10;j++)
for(k=0;k<10;k++)
Field[j][k]=0;
}

and so on there are many many ways .... to get the result
or zeroing Out every array at Initizialization....
void main()
{
unsigned cahr Field[3][10][10]={0};
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This Forums has a bug ....
The misatke is in my Post at :
for (...) //i
for( ....) //j
for( ...) //j

Field (i)(j)(k)=0; //Replace here angle brackets with index bracket this is the correct code line , this forzum has a bug with []-Brackets ..........

Share this post


Link to post
Share on other sites
The easiest way to initialize an array to a single value is to use a function called memset. Here is an example of how it''s used:

memset( map, 0 ,( 3* 10 * 10 * sizeof( int )) );

This would set all values in that array you made to 0.

Share this post


Link to post
Share on other sites
In order to get [ i ] to show up correctly, you have to include in inside of [ source] [ /source] (or [ code] [ /code]) tags. This is becuase [ i] [ /i] indicates a block of italics.

  
for(int i=0; i<3; i++)
for(int j=0; j<10 ;j++)
for(int k=0; k<10; k++)
array[i][j][k] = 0;



Magmai Kai Holmlor
- Not For Rent

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!