Run error in some test cases

my program is showing srror in some test case what is the problem…
my code:

#include
using namespace std;
class node
{
public:
int data;
node* next;
//constructor
node(int d){
data=d;
next=NULL;
}
};
void insertAtTail(node*&head,int data){
if(head==NULL){
head=new node(data);
return;
}
node* temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=new node(data);
return;
}
node* buildlist(node*& head,int n){
while(n–)
{
int data;
cin>>data;
insertAtTail(head,data);
}
}
node* append(node*&head,int k){
node* fast=head;
node* slow=head;
for(int i=1;i<=k;i++){
fast=fast->next;
}
while(fast->next!=NULL){
fast=fast->next;
slow=slow->next;
}
nodec=slow->next;
slow->next=NULL;
fast->next=head;
return c;
}
void print(node
head){
node* temp=head;
while(temp!=NULL){
cout<data<<" ";
temp=temp->next;
}
}
int main() {
int n;
cin>>n;
node* head=NULL;
buildlist(head,n);
int k;
cin>>k;
head=append(head,k);
print(head);
}

Hi @sawan_verma
You are facing run error for cases where k>n. So to avoid this before call append function just do k%n so that k<n. And also when k==n then in append function your c is becoming NULL due to which there is no output.

Here is your corrected code :