c array question
Aug 15, 2007 at 7:56 PM Thread Starter Post #1 of 2

NotoriousBIG_PJ

Step 1: Plug power cable into wall. Step 2: Plug other end of power cable into....umm.... Step 0.5: Order something to power with power cable.
Joined
Mar 12, 2002
Posts
3,487
Likes
22
How do I make something like the following code work (without doing a loop)?

int gamePeiceCurr[4][4];
int gamePeices[7][2][4][4];
....
gamePeiceCurr = gamePeices[0][0];
//so that gamePeiceCurr[j] == gamePeices[0][0][j]

Thanks,

Biggie.
 
Aug 15, 2007 at 9:54 PM Post #2 of 2
It's been a while since I used C so the syntax may be wrong.

One way is nested loops.

Code:

Code:
[left]for (int i=0;i<max? ; i++) { // can't remember how to do the max for an array for (int j=0;j<max?;j++) { gamePeiceCurr[i][j] == gamePeices[0][0][i][j]; } }[/left]


There might be another way with a pointer to gamePeiceCurr and another to gamePeices[0][0]. It would depend on how the data is stored in memory. This would be the true, god awful, C programmers way to do it. So that if you change compilers, hardware, operating systems, etc., the code may or may not work.

I've seen this happen where I work when we went from 32bit HPUX to 64bit HPUX. We had some undocumented, uncommented code written by a programmer that was long gone, that did a lot of memory manipulation with pointers. None of it worked and it was next to impossible to figure out what the code was even trying to do.

If you can't tell, I'm not a fan of C. My favorite C book describes all the ways you can get yourself in trouble in C. It's called "Enough Rope to Shot Yourself in the Foot"
very_evil_smiley.gif
 

Users who are viewing this thread

Back
Top