PDA

View Full Version : Need immediate help please


RubberSoul_Guy
November 10th, 2005, 05:20 AM
Does anyone have any C code to make a global array group of a game board with 9 columns, 9 rows and 9 subsquares?

it'll be in a method called void makegroups() or something similar.

Please help im desperate. I really need this so any help would be very appreciated.

thanks.

Eclectifish
November 10th, 2005, 06:29 AM
You don't want me to do your homework for you do you? :)

I don't have a lot of time to do this, and I'm not quite sure of what your objective is, but I think you'll want a 3D array (never heard it called a group -- it's a matrix)

Anyway...

int[] anGroup = new int[9,9,9];

or

int[9,9,9] anGroup = new int[];

I think.

I don't do C that regularly, mostly I'm in C# and Java these days. Actually, what I wrote is more C++ anyway. I just used int because it's easy. If you're in C++ you might want to create a class and then declare and array of class.

I'm just really talking off of the top of my head here since I haven't done this in a while and don't normally create more than a single dimensional array. But that should be a good jumping off point. If I have time, I'll research it a little more.

RubberSoul_Guy
November 10th, 2005, 07:26 AM
Thanks for the reply!!

What i've done so far is this.

void makegroups()
{
int row, col:
for(row = 0; row <9; row++){
Cellgroup cellgroup;
for(col = 0; col <9; col ++){
Coord coord;
coord.r = row;
coord.c = col;

cellgroup.grp[col] = coord;
}

group[row] = cellgroup;
}

END

Cellgroup has already been declared in another file e.g
extern Cellgroup group[27]; // and its the only global variable.

ALSO,

typedef struct TCoord Coord;
struct TCoord{
int r;
in c;
};

is also in there to declare the coordinates.

Thats just a bit of extra info if you need it. Thanks for the effort.

Eclectifish
November 10th, 2005, 01:13 PM
Yeah, I think you definitly need to make this a 3D matrix, though.

I had to look this up (I'm so used to C# now it's sick). Here's what you want to do, more or less (this is C++, though, but no-one really uses Ansi C any more if they can help it):

Coord coord[9][9][9]; // this creates your 3D matrix of Coord structs - although in C++ if you can, use class

Use the loops to populate the matrix, not to create.

RubberSoul_Guy
November 10th, 2005, 01:55 PM
thanks for that. I appreciate someone helping.