代码在运行总出现Segmentation fault (core dumped),想知道我是哪里错了
在dev上编译没问题但是在学校系统上就出问题了
#include<stdio.h>
#include<stdlib.h>
#define OK 1
typedef int Status;
typedef struct LNode{
int data;
struct LNode *next;
}LNode;
LNode* InitList_L(LNode *L){
L=(LNode*)malloc(sizeof(LNode));
L->next=NULL;
return L;
}
LNode *CreateList_F(LNode *L,int n){
LNode *p=L;
for(int i=0;i<n;i++){
LNode *s=(LNode *)malloc(sizeof(LNode));
scanf("%d",&s->data);
s->next=p->next;
p->next=s;
}
return L;
}
LNode *TraverseList_L(LNode *L){
LNode *p=L->next;
while(p!=NULL){
printf("%d",p->data);
if(p->next!=NULL){
printf(",");
}
p=p->next;
}
return L;
}
LNode *DestroyList_L(LNode *L){
LNode *p,*q;
p=L->next;
q=p->next;
while(p!=NULL){
free(p);
p=q;
q=q->next;
}
return L;
}
int main(){
LNode *L;
int n;
L=InitList_L(L);
scanf("%d",&n);
L=CreateList_F(L,n);
L=TraverseList_L(L);
L=DestroyList_L(L);
return 0;
}