ERROR: segmentation fault (core dumped)
when i am trying to run this program on ubuntu it compiles but when i run it it flags as "segmentation fault (core dumped)". can anyone tell me how to get the output.the code is as follows:
Code:
#include<stdio.h>
#include<stdlib.h>
struct node{
int info;
struct node*link;
};
void append(struct node**, int);
void displ(struct node*);
void append(struct node **q, int n){
struct node *temp,*r;
if(*q==NULL){
printf("the list has zero elements and the first node being added is %d\n",n);
temp->info=n;
temp->link=NULL;
*q=temp;
}
else
{temp=*q;
while(temp->link!=NULL)
temp=temp->link;
r=malloc(sizeof(struct node));
r->info=n;
r->link=NULL;
temp->link=r;
}
}
void displ(struct node *q){
struct node *p;
for(p=q;p->link!=NULL;p=p->link)
printf("%d",p->info);
}
main(){
struct node *p;
int n;
p=NULL;
printf("enter value to append a node\n");
scanf("%d",&n);
//append(&p,12);
displ(p);
}
:frown: