2d arrays

Steven Arthur Sivier sasg0244 at uxa.cso.uiuc.edu
Thu Mar 14 04:38:07 AEST 1991


i've always tried to avoid 2d arrays, but because of a library
function i need to call i need to use 2d arrays. the problem
is i have to malloc the 2d array. can i just malloc the array
to a char pointer and then use it as a 2d array? that is, if
the array has dimensions x by y can i use:
	char *array;
	array = malloc(x * y);
	array[0][0] = 'a'

also, inasmuch as i need to pass this array to a library function,
can i just send the pointer even though the function expects a
2d array?

sorry if this seems like a stupid question, but i usually just
kludge around the very few times i've needed multi-dimensional
arrays.

thanks
steve sivier
sasg0244 at uxa.cso.uiuc.edu



More information about the Comp.lang.c mailing list