求指点实现链表的数据存入程序不知道那里错了
七十四路很简单 就是先创建一个链表然后在主函数调用 然后再主函数里向链表存入数据不知道那里错了。求指点#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct node
{
int data;
struct node *next;
}pnode,*pnext;
int len;
pnext creatlist()
{
int i,val;
pnext phead=(pnext)malloc(sizeof(pnode));
if(phead==NULL)
{
printf("创建失败\n");
exit(-1);
}
pnext ptail=phead;
printf("请输入链表个数=");
scanf("%d",&len);
for(i=0;i<len;i++)
{
pnext pnew=(pnext)malloc(sizeof(pnode));
if(pnew==NULL)
{
printf("创建失败\n");
exit(-1);
}
pnew->data=val;
ptail->next=pnew;
pnew->next=NULL;
ptail=pnew;
}
return phead;
}
int main()
{
int i,val;
pnext phead=(pnext)malloc(sizeof(pnode));
pnext p=phead;
creatlist();
printf("请输入值");
scanf("%d",&val);
for(i=0;i<len;i++)
{
p=(pnext)malloc(sizeof(pnode));
p->data=val;
p=p->next;
}
printf("链表:%d",p->data);
}