简单链表问题,求教
这是一个创建链表的程序,可是不知道为什么运行的时候会出错,错误在for 循环的
L->next = NULL语句上,兄弟们帮我看看,vs和dev-c++上都有错,编译是可以通过的
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
struct LNode
{
int number;
struct LNode *next;
}*Linklist;
void CreatList(struct LNode *L,int n)
{
int i;
for(i= n;i>0;--i)
{
struct LNode *p;
p = (struct LNode *)malloc(sizeof(struct LNode));
printf("please enter the int:");
scanf("%d",&p->number);
printf("%d",(*p).number);
// p->next = L->next;
L->next = NULL;
//printf("/n the number %d struct is succesfull", i);
}
}
int main(int argc, char *argv[])
{
struct LNode *L;
L = (struct LNode *)malloc(sizeof(struct LNode));
L->next = NULL;
CreatList(Linklist,3);
system("PAUSE");
return 0;
}