Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Dynamic array of matrices

Reply
Thread Tools

Dynamic array of matrices

 
 
Prototipo
Guest
Posts: n/a
 
      11-01-2003
Hi! I need to dynamically create X vectors of matrices (with a known
size of 5x5). It's like a three-dimensional matrix with 2 known
dimensions and the third unknown.

I have something like:

int *matrix[5][5];

But I don't know how to allocate memory for X matrices. How can I do
it?

thanks
 
Reply With Quote
 
 
 
 
Tom St Denis
Guest
Posts: n/a
 
      11-01-2003

"Prototipo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi! I need to dynamically create X vectors of matrices (with a known
> size of 5x5). It's like a three-dimensional matrix with 2 known
> dimensions and the third unknown.
>
> I have something like:
>
> int *matrix[5][5];
>
> But I don't know how to allocate memory for X matrices. How can I do
> it?


The same way you do with all other matrices

matrix = calloc(X, sizeof(matrix[0]));

Tom


 
Reply With Quote
 
 
 
 
Artie Gold
Guest
Posts: n/a
 
      11-01-2003
Prototipo wrote:
> Hi! I need to dynamically create X vectors of matrices (with a known
> size of 5x5). It's like a three-dimensional matrix with 2 known
> dimensions and the third unknown.
>
> I have something like:
>
> int *matrix[5][5];
>
> But I don't know how to allocate memory for X matrices. How can I do
> it?
>


See:

http://www.eskimo.com/~scs/C-faq/q6.16.html

[You *did* read the various FAQs *first*, didn't you? ]

HTH,
--ag
--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

 
Reply With Quote
 
dis
Guest
Posts: n/a
 
      11-01-2003
"Prototipo" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...

> Hi! I need to dynamically create X vectors of matrices (with a known
> size of 5x5). It's like a three-dimensional matrix with 2 known
> dimensions and the third unknown.
>
> I have something like:
>
> int *matrix[5][5];
>
> But I don't know how to allocate memory for X matrices. How can I do
> it?



#include <stdlib.h>
int main(void)
{
int X = 5;
int (*matrix)[5][5] = malloc(X * sizeof *matrix);
if (matrix != NULL)
{
/* allocation succeeded */
}
free(matrix);
return 0;
}



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
implementing matrices using 2D dynamic memory vs. using vectors ssylee C++ 2 01-14-2009 09:36 PM
The Truth About Matrices , a Real Eye Opener ! nallspaid Computer Support 2 03-30-2005 02:49 AM
matrices tommy C++ 3 12-03-2004 09:17 PM
C binding to transfer matrices from C to Python and from Python toC Nils Wagner Python 1 10-22-2004 07:52 PM
split matrices mkokelma VHDL 5 10-22-2004 10:46 AM



Advertisments