求大神帮忙解答一下
# include <stdio.h># include <stdio.h>
# include <stdlib.h>
typedef struct Node {
int data;//数据域
struct Node * pNEXT;//指针域
}NODE, *PNODE;
PNODE create_list(void);
void traverse_list (PNODE pHead);
int main (void)
{
PNODE pHead;
pHead = NULL;
pHead = create_list();//创建一个非循环单 链表
traverse_list (pHead);
return 0;
}
PNODE create_list(void)
{
int i;
int len;
int val;
PNODE pHead = (PNODE)malloc(sizeof(NODE)) ;
if (NULL == pHead)
{
printf("分配失败,程序终止!\n");
exit (-1);
}
PNODE pToli = pHead ;
pToli->pNEXT = NULL;
pHead->pNEXT = pToli;
printf ("请输入你要分配的节点个数: len = ");
scanf ("%d",&len);
for (i = 0; i < len; ++i)
{
printf("请输入第%d个节点的值",i+1);
scanf("%d",val);
PNODE pNew = (PNODE)malloc(sizeof(NODE)) ;
if (NULL == pNew)
{
printf("分配失败,程序终止!\n");
exit (-1);
}
pNew->data = val;
pToli->pNEXT = pNew;
pNew->pNEXT = NULL;
pToli = pNew;
}
return pHead;
}
void traverse_list (PNODE pHead)
{
PNODE p = pHead->pNEXT;
while ( NULL != p)
{
printf ("%d ", p->data);
p = p->pNEXT;
}
printf("\n");
}
为什么只能输入一个节点的值 第二个就不行了