Re: Array setup Question
- From: "Jake Thompson" <readytoride39@xxxxxxxxxxx>
- Date: 21 Mar 2006 10:56:18 -0800
Hello guys I made the following changes to my code based upon what I
read and the input that you guys gave me
my structure with all char * values
struct cm8linkstruc
{
char *type; /* type of item*/
char *desc; /* description of item */
char *item_increment; /*increment value for item
in folder */
char *itemid; /* id of returned item */
};
struct cm8linkstruc cm8link;
Sample of code
/*Allocate the structure */
cm8link = malloc(sizeof cm8link * fcount);
if(!cm8link)
{
return 1;
}
for(h = 0; h< fcount ; h++)
{
cm8link[h] = malloc(sizeof (cm8link[h]));
cm8link[h]->type = 0;
cm8link[h]->desc = 0;
cm8link[h]->item_increment = 0;
cm8link[h]->itemid = 0;
}
l_stat = u_cm8_getfolditemmatch((PITEMID)cptr, &cm8link);
if(l_stat)
{
/*clean it structure and free it*/
for(h = 0; h< fcount ; h++)
{
u_free_uni(cm8link[h]->type);
u_free_uni(cm8link[h]->desc);
u_free_uni(cm8link[h]->item_increment);
u_free_uni(cm8link[h]->itemid);
free(cm8link[h]);
}
return(1);
}
Originally I was going to make the cm8linkstruc part of another
structure like this
struct cm8rcstruc
{
BOOLEAN checkedout; /* status of checked
out object*/
char *userid; /* user who has object
checked out */
short objtype; /* True is a folder
\False is not */
char *note; /* Returned note */
struct cm8linkstruc *u_cm8link; /*pointer to link
structure*/
};
That is why I had so many stars. I since changed my mind and just want
to make the cm8linkstruc it's own structure without being part of
another structure. By doing that I believe my indirection gets messed
up
so instead of defining the structure as
struct cm8linkstruc **cm8link;
I now define it as
struct cm8linkstruc cm8link;
which like I said messes up my indirection for my mallocs correct. How
can I fix this?
Also when doing the free of the structure I free each char * in the
array. This to me means that I have to allocate the char * in a
similar fashion which I am not currently doing because all I do on the
allocation is set everything to 0 when I think I should be doing
something more involved - Can someone show me an example?
Sorry for all the questions but I derailed very easy with allocations
and indirections and I am just trying to get back on track.
Thanks
Jake
.
- Follow-Ups:
- Re: Array setup Question
- From: Ben C
- Re: Array setup Question
- From: Keith Thompson
- Re: Array setup Question
- References:
- Array setup Question
- From: Jake Thompson
- Array setup Question
- Prev by Date: Re: "Shifting" floating point numbers
- Next by Date: Re: "Shifting" floating point numbers
- Previous by thread: Re: Array setup Question
- Next by thread: Re: Array setup Question
- Index(es):