链表找错 编译链接无错 输入后有错
程序代码:
#include<stdio.h> #include<stdlib.h> struct test { int num; struct test *next; }; int main(int argc,char *argv[]) { struct test* init(); void relp(struct test *head); struct test *head; head=init(); relp(head); return 0; } struct test* init() { struct test *head,*p,*t; printf("依次输入各值\n"); head=(int *)malloc(sizeof(int)); scanf("%d",&head->num); p=t=head; p->next=NULL; while(p->num!=0) { t=(int *)malloc(sizeof(int)); scanf("%d",&t->num); p->next=t; p=t; } p->next=NULL; return head; } void relp(struct test *head) { struct test *p; p=head; while(p->next!=NULL) { free(p); p=head->next; head=head->next; } printf("释放完毕\n"); return 0; }求指教