how to allocate memory for struct itself, and its members

Posted by Jack on Stack Overflow See other posts from Stack Overflow or by Jack
Published on 2012-09-02T15:13:12Z Indexed on 2012/09/02 15:38 UTC
Read the original article Hit count: 162

Filed under:
|
|

I have this struct:

struct foo {
  char *a;
  char *b;
  char *c;
  char *d;
};

it's possible allocate space for struct itself and its members instead of e.g,

struct foo f;
f.a = malloc();
f.b = malloc();
f.c = malloc();
f.d = malloc();
strcpy(f.a, "a");
strcpy(f.b, "b");
//..

something like this(of couse that it doesn't works):

struct foo f = malloc(sizeof(struct f));
strpcy(f.a, "a");
//etc

© Stack Overflow or respective owner

Related posts about c

    Related posts about struct