arrays - C how to modify memory of structs that are inside other structs -
if have 2 structs:
typedef struct{ unsigned int time; double rate; }quote; typedef struct{ unsigned int freeslots; unsigned int end; unsigned int start; unsigned int currsize; unsigned int maxsize; unsigned int startat; //unsigned int currindex; quote quotebuffer[1]; }cbuf;
and wanted make function modify size of quotebuffer array inside cbuf, how go doing that? have tried few approaches none have worked far. keep returning same format of:
quote *newquotebuffer = malloc(sizeof(quote) * newsize);
and if have existing cbuf somewhere (for example, call "a" pointer cbuf):
a->quotebuffer = newquotebuffer;
but doesn't work. hints?
this:
quote quotebuffer[1];
should be:
quote *quotebuffer;
then assignment work.
dereferencing quote
looks this:
a->quotebuffer->time;
if later have multiple elements of quote allocated malloc() can access them this:
a->quotebuffer[i].time;
Comments
Post a Comment