#include
#include
typedef struct _node{
int value;
struct _node *next;
}Node;
int main(int argc,char const *argv[])
{
Node *head=NULL;
- int number;
- do{
- scanf("%d",&number);
- if(number!=-1){
- Node *p=(Node*)malloc(sizeof(Node));
- p->value=number;
- p->next=head->next;
- head->next=p;
- }
- }while(number!=-1);
-
- for(Node *q=head->next;q;q=q->next){
- printf("%d",q->value);
- }
-
- for(Node *p=head;p;p=p->next){
- free(p);
- }
-
- return 0;
}
只能运行到第一次输入,卡在p->next=head->next;
以及Program received signal SIGSEGV, Segmentation fault.
是因为head的next为NULL吗?