Created
April 20, 2012 14:30
-
-
Save zarch/2429080 to your computer and use it in GitHub Desktop.
Cycle for, for a 2d array given the pointer to the first element of the array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <stdio.h> | |
typedef struct __move__ | |
{ | |
short int length; | |
short int *mv; | |
short int *dir; | |
double *dist; | |
} move; | |
short int mv[8][2] = | |
{ | |
{ 1, 1}, /* 1 */ | |
{ 1, 0}, /* 2 */ | |
{ 1, -1}, /* 3 */ | |
{ 0, 1}, /* 4 */ | |
{ 0, -1}, /* 6 */ | |
{-1, 1}, /* 7 */ | |
{-1, 0}, /* 8 */ | |
{-1, -1}, /* 9 */ | |
}; | |
short int dir[8] = {1, 2, 3, 4, 6, 7, 8, 9}; | |
double dist[8] = {M_SQRT2, 1, M_SQRT2, 1, 1, M_SQRT2, 1, M_SQRT2}; | |
move movement = {8, mv[0], dir, dist}; | |
int row; | |
int main() | |
{ | |
short int row_example[2], j; | |
for ( row = 0; row < movement.length; row++ ) | |
{ | |
/* | |
* *( *( mat # i) # j) | |
* *( mat + i * sizeof( row ) + j * sizeof( T ) ) | |
*/ | |
printf ( "%d) mv0=%d mv1=%d\n", | |
row, | |
* ( movement.mv + row * sizeof( row_example )) , | |
* ( movement.mv + row * sizeof( row_example ) + sizeof( j ))); | |
} | |
return 0; | |
} | |
int main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment