Q
qianz99
Hi I have a very complicated struct
typedef struct F {
int a_len;
struct A *a[32] /* OPTIONAL */;
B b;
C *c /* OPTIONAL */;
D *d /* OPTIONAL */;
E *e /* OPTIONAL */;
} F_t
A,B,C,D,E are all struct for instance
typedef struct A{
int len;
unsigned char addr[9];
}A_t
And I have another structure on top of F
typedef struct G{
int len;
F_t F[32];
}G_t
typedef struct H{
....
G_t *g;
}H_t
I have thinking of writing a function to evaluate struct F, and when I
eveluate struct H, I will call this function.
I use malloc in the function to evaluate F, will it cause any problem?
will the point link lost when I exit this function?
void evluate_F(F_t *f, ...)
{
char *tmp;
int i;
A_t tmpA;
f->a_len = 10;
for(i=0;i<;f->a_len;i++)
{
strcpy(tmpA.addr,"1234");
tmpA.len = strlen(tmpA.addr);
if((tmp=malloc(sizeof(A_t)))!=NULL)
{
memcpy(tmp,tmpA,sizeof(tmpA));
f->a = tmp;
}
}
.....
}
Thanks a lot
typedef struct F {
int a_len;
struct A *a[32] /* OPTIONAL */;
B b;
C *c /* OPTIONAL */;
D *d /* OPTIONAL */;
E *e /* OPTIONAL */;
} F_t
A,B,C,D,E are all struct for instance
typedef struct A{
int len;
unsigned char addr[9];
}A_t
And I have another structure on top of F
typedef struct G{
int len;
F_t F[32];
}G_t
typedef struct H{
....
G_t *g;
}H_t
I have thinking of writing a function to evaluate struct F, and when I
eveluate struct H, I will call this function.
I use malloc in the function to evaluate F, will it cause any problem?
will the point link lost when I exit this function?
void evluate_F(F_t *f, ...)
{
char *tmp;
int i;
A_t tmpA;
f->a_len = 10;
for(i=0;i<;f->a_len;i++)
{
strcpy(tmpA.addr,"1234");
tmpA.len = strlen(tmpA.addr);
if((tmp=malloc(sizeof(A_t)))!=NULL)
{
memcpy(tmp,tmpA,sizeof(tmpA));
f->a = tmp;
}
}
.....
}
Thanks a lot