链表输出不了 帮看下 谢谢
#include<stdio.h>#include<malloc.h>
#include<stdlib.h>
typedef struct node
{ int date;
struct node *pnext;
}NODE,*PNODE;
//111
void creat_list(int);
void trave_list(PNODE);
PNODE phead;
//主函数
void main()
{ creat_list(10);
//trave_list(phead);
}
//创建链表
void creat_list(int length)
{ phead=(PNODE)malloc(sizeof(NODE));
if(phead==NULL)
{printf("内存分配失败\n");
exit(-1);
}
PNODE pnew,pt;
for(int i=1;i<=length;i++)
{ pnew=(PNODE)malloc(sizeof(NODE));
if(pnew==NULL)
{printf("内存分配失败\n");
exit(-1);}
if(i==1)
{phead->pnext=pt=pnew;
int val;
printf("输入第%d值\n",i);
scanf("%d",&val);
pnew->date=val;
pnew->pnext=NULL;
}
else
{ int val;
printf("输入第%d值\n",i);
scanf("%d",&val);
pnew->date=val;
pt->pnext=pnew;
pt=pnew;
pt->pnext=NULL;
}
}
printf("创建成功\n");
printf("%d\n",pnew->date);//为什运到这里停了
PNODE p;
phead->pnext=p;
{printf("%d\n",po->date);
/*while(p!=NULL)
{printf("%d\n",p->date);
p=p->pnext;
}
}}