How to use serial indexed array as multi dimensional one?

How to use 1-dimensional array as if it is 2-dimensional one?
xnum is maximum num of x-direction.

2darray[y*xnum+x]
  • how to calculate 2d index from serial number?

so I defined this Macro

#define GETINDEX(_x,_y) _y*XMAX+_y
for(int serial=0;serial<length;serial++){
x=serial%xnum;
y=serial/xnum;
}
en.gif en
ja.gif ja


edit
サポートサイト Wikidot.com