pointer to a pointer to a struct
From: Bert (maatjesharing_at_gmx.de)
Date: 06/30/04
- Next message: Mike Wahler: "Re: QUESTIONS ANSWERED"
- Previous message: who: "Re: how can I read tring and numbers from a file?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Jun 2004 10:10:01 -0700
I'm trying to dynamically declare and initialize a table of structs.
While searching for information, I found this message:
http://groups.google.com/groups?selm=3a6dffdb%240%24273%40newsreader.alink.net
Quote:
#include <stdlib.h>
struct mystruct {
char structelement1;
char structelement2;
};
int main (void) {
int rows = 100;
int columns = 100;
struct mystruct **array;
int x;
array = malloc(sizeof(*array) * rows);
for (x=0; x < rows; x ++) {
array[x]=malloc(sizeof(**array) * columns);
}
/* now do something with it... */
}
End of Quote
Is this a valid way to allocate memory for the structs?
- Next message: Mike Wahler: "Re: QUESTIONS ANSWERED"
- Previous message: who: "Re: how can I read tring and numbers from a file?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|