
HELP! Multidimensional array won't work
to make a[50][60], try this...
int i;
float **a;
a = (float **) calloc( 50, sizeof(float *));
if( a==NULL ) error();
for(i=0; i<50; i++){
a[i] = (float *) calloc( 60, sizeof(float));
if( a[i] == NULL ) error();
Quote:
}
if want to keep between successive calls, remember to make static, such as:
static float **a = NULL;
if( a==NULL ){
//allocate here
Quote:
} else {
//re-initialize matrix here
Quote:
}
to free, repeat above in opposite order, (free all a[i] first, then free (a),
else you have memory leak )
the 2d matrix here is an array of pointers, each pointing to a vector. Can
scale to whatever dimension you need.
if dont need to store matrix between successive calls, remember that calloc is
relatively slow operation, so keeping
as static speeds execution, if matrix is same size or smaller, and not too
large, keep it.
brian
Quote:
> Hey there,
> I'm having trouble with multidimensional arrays. I want to use a float
> array of size 50x50 in a program, but when I've done this and run it,
> my computer screen goes blue. The largestest mulidimensional array I've
> been able to use is one that was 42x10(doesn't always work at that
> size). How can I create a multidimensional array of the size I need?
> * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
> The fastest and easiest way to search and participate in Usenet - Free!