Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

malloc, once again

Name: Anonymous 2010-11-03 8:25

I have a struct like
typedef struct { char* dildo; int etc } anus;.
Later on I want to make an anus array, with dildo being a string entered by the user.
Now how do I reserve the memory for dildo in my anus array?

So far I have:

typedef struct { char* dildo; int etc } anus;
...
char* small_dildo = fancy_input_routine();
anus* anii = (anus*) malloc(array_size * sizeof(anus));

With that I can't memcpy any small_dildo into my anii obviously, however I'm not quite sure how to do it.

Name: Anonymous 2010-11-03 11:43

typedef struct
{
  int etc;
  char under_18_acceptable_name[0];
} GNU_ENTERPRISE;


char *str = "hi there";
GNU_ENTERPRISE *p = malloc(sizeof(*p) + strlen(str) + 1);
if(!p)
  die("you suck");

strcpy(p->under_18_acceptable_name, str);
p->etc = 3;


etc

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List