69,368
社区成员
发帖
与我相关
我的任务
分享
typedef struct test test;
typedef struct rule rule;
struct test
{
int a;
char *param;
};
test array[10];
struct rule
{
test *first;
int b;
rule *msr;
};
int main(int argc, char **argv)
{
rule *sec_rule;
char *s1 = "hello";
char *s2;
s2 = (char *)malloc(3);
memcpy(s2, s1, 2);/*只要前面的he*/
sec_rule = (rule *)malloc(sizeof(rule));
memset(sec_rule, 0, sizeof(rule));
memset(array, 0, 10*sizeof(test));
sec_rule->first = array;
(sec_rule->first).a = 1;
(sec_rule->first).param = (char *)malloc(strlen(s1) + 1);
memcpy((sec_rule->first).param, s1, strlen(s1));
(sec_rule->first)[1].a = 2;
(sec_rule->first)[1].param = (char *)malloc(strlen(s2) + 1);
memcpy((sec_rule->first[1]).param, s2, strlen(s2));
sec_rule->b = 1;
char *temp = (char *)sec_rule;/*在这强制转化*/
/*free暂时不管啦,退出时自己free吧*/
return 0;
}