主题:linux下指针报段错误
各位大侠好:
最近写了个程序 在linux下运行报段错误 ,请高手帮忙看看,多谢了 代码如下
#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 *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;
printf("element->attrs->name=[%s]\n",element->attrs->name);
return 0;
}