链表添加节点问题
1
//此函数用于添加一个节点 void Addlink(struct Date * head) { struct Date * newone,* p; newone = (struct Date *)malloc(sizeof(struct Date));//为新节点分配内存 for(p=head;p!=NULL;p=p->next) //找出最后一个节点 ; p->next = newone; //让原来最后的节点指向新节点 printf("请输入新节点的值:"); scanf("%d",&newone->num); newone->next = NULL; //完成后让新节点指向NULL printf("添加节点成功!\n"); }
上面的函数用于添加一个节点,为什么p->next=newone这里会出问题呢?