关于链表错误
创建一个简单的链表后,编译也能通过,但输出链表时总是有错误为什么?#include<stdio.h>
#include<stdlib.h>
struct list
{
int data;
struct list *next;
} *Link;
void Creat_List(list *Link);
void Print_list(list *Link);
main()
{
Creat_List(Link);
printf("the list has been created\n");
getchar();
Print_list(Link);
}
void Creat_List(list *Link)
{
printf("to creat the list\n");
char c='y';
int t;
list *p,*q;
Link=q=(list *)malloc(sizeof(list));
while(c=='y')
{
printf("input the data:\t");
scanf("%d",&t);
p=(list *)malloc(sizeof(list));
p->data=t;
q->next=p;
q=p;
q->next=NULL;
printf("press 'y' to continue or 'n' to exit\n");
getchar();
c=getchar();
}
}
void Print_list(list *Link)
{
list *p;
p=Link->next;
while(p)
{
printf("%d\t",p->data);
p=p->next;
}
printf("\n");
}