pointer to a pointer to a struct

From: Bert (maatjesharing_at_gmx.de)
Date: 06/30/04


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?



Relevant Pages

  • Re: Getting NASM from C
    ... *) When translating structs, ... STD NOHIDE {int nosys;} syscall nosys_args int ... MSTD NOHIDE {void sys_exit;} exit ... MSTD POSIX {ssize_t read(int fd, void *buf, size_t ...
    (alt.lang.asm)
  • Re: passing structs in and out of functions
    ... > I can pass my information into the structs with no major difficulties, ... > void render ... int main ... parentheses to deal with the higher precedence of the Dot operator. ...
    (comp.lang.c)
  • Re: Use of diff pointers
    ... void main returns int. ... Please quote enough of the previous message for context. ...
    (comp.lang.c)
  • Re: attempting to compile with Paul Smedleys build environment
    ... pttrace.c:359: error: void value not ignored as it ought to be ... Quote about 10 lines either side of it too ... int result; ...
    (comp.os.os2.programmer.porting)
  • Re: Win AP question
    ... This means that you can't just pass an array of structs. ... memory which is large enough for the structs and the string data. ... public static extern int EnumJobs( ... > public string pPrinterName; ...
    (microsoft.public.dotnet.languages.csharp)