提示段错误,但不知道错哪了
#include <stdio.h>#include <stdlib.h>
struct ListNode {
int data;
struct ListNode *next;
};
struct ListNode *createlist()
{
struct ListNode *p[30];
int i,number,n,j;
i=-1;
for(j=0;j<30;j++)
p[j]=NULL;
scanf("%d",&number);
while(number!=-1){
i++;
p[i]=(struct ListNode*)malloc(sizeof(struct ListNode));
p[i]->data=number;
scanf("%d",&number);
}
n=i;
while(i!=0)
{
p[i]->next=p[i-1];
i--;
}
p[0]->next=NULL;
return p[n];
}
int main()
{
struct ListNode *p, *head = NULL;
head = createlist();
for ( p = head; p != NULL; p = p->next )
printf("%d ", p->data);
printf("\n");
return 0;
}