c链表问题
自己写了个链表,编译通过后,运行报内存错误(unix下)请教大家
int n=2,m;
struct type
{
char name[50+1];
struct type *next;
};
struct type *first,*p;
strcpy(first->name,"zhangfeng");
p=first;
for(m=0;m<n;m++)
{
first->next=(struct type *)malloc(100);
strcpy(first->next->name,"hanzb");
first=first->next;
}
printf("%s \n",p->name);
printf("%s \n",p->next->name);
free(p->next);
free(p);