主题:结构体指针程序报段错误 请帮忙看下
再linux下编译并执行下面的程序 程序直接core掉 请高手看下是什么原因 谢谢
#include <stdio.h>
#include <stdlib.h>
typedef struct mxml_attr_s
{
char *name;
char *value;
} mxml_attr_t;
typedef struct mxml_element_s
{
char *name;
int num_attrs;
mxml_attr_t *attrs;
} mxml_element_t;
int main ()
{
mxml_element_t * element = NULL;
char str1[64]={0};
char str2[64]={0};
char *name = NULL;
if ((element= calloc(1, sizeof(mxml_element_t))) == NULL)
{
printf(" calloc error ");
return (NULL);
}
sprintf(str1,"%s","ns4:attrbutename");
name=str1;
printf("str1=[%s]\n",str1);
printf("name=[%s]\n",name);
element->attrs->name=name;
memcpy(str2,element->attrs->name,sizeof(str2));
printf("element->attrs->name=[%s]\n",element->attrs->name);
return 0;
}