multidimensional arrays
cottrell at nbs-vms.ARPA
cottrell at nbs-vms.ARPA
Sat Jan 12 02:39:44 AEST 1985
/*
okay, so you want to specify the dimensions at runtime? try this:
#define ROWS some constant
#define COLS some constant
int a[ROWS][COLS];
main()
{ func(a,3,5);
func(a,6,4);
}
#define A(x,y) *(a + x*j + y)
func(a,i,j)
int a[1];
{ int p,q;
for (p = 0; p < i; p++)
for (p = 0; p < i; p++) { /* row loop */
for (q = 0; q < j; q++){/* col loop */
printf("%d\t",A(p,q));
} printf("\n");
}
}
see if that doesn't get you two dimensions for one. the only problem is
that the address of an array element cannot be taken. to do that you need:
#define A(x,y) a[x*j + y]
hey, why didn't i just say that in the first place?
*/
More information about the Comp.lang.c
mailing list