Getting error /bin/run.sh: line 4: 18 Segmentation fault (core dumped) ./exe

my code
#include
using namespace std;
class node{
public:
int data;
node* next;

node(int val)
{
	data=val;
	next=NULL;
}

};

void insert(node*&head,int x){
if(head==NULL){
head=new node(x);
return;
}
node* cur=head;
while(cur->next!=NULL){
cur=cur->next;
}
cur->next=new node(x);
return;
}
void buildlist(node &head,int n){
int data;
cin>>data;
while(n>0){
cin>>data;
insert(head,data);
n–;
}
}
void print(node
head){
node* temp=head;
while(temp->next!=NULL){
cout<data<<" ";
temp=temp->next;
}
}
node* append(node* head,int n,int k){
node* curr=head;
node* prev=head;
for(int i=0;i=(n-k);i++){
prev=curr;
curr=curr->next;
}
prev->next=NULL;
node* temp=curr;
while(temp->next !=NULL){
temp=temp->next;
}
temp->next=head;
return curr;

}
int main() {
int n;
cin>>n;
node* head=NULL;
buildlist(head,n);
int k;
cin>>k;
head=append(head,n,k);
print(head);
return 0;
}

share code in CB ide

what was the problem in my code

share code in cb ide
hard to debug this way

@toshitvarshney11

sirrr please share the code which has not error ( syntax error)
i could have also copied the above one
thats how i get this code when u simply copy paste
image

kafi glti h
buildList function is malfunctioning
kappend has a wrong logic

that is why you get a segmentatio fault

ie accessing memory outside permissible allocated values

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.