Linked List-K Append

#include
using namespace std;

typedef struct node{
int info;
node *next;
}node;

node * insertAtTail(node*head, int data){
node p = (node)malloc(sizeof(node)) ;
p->info = data;
p->next = NULL;
if(head==NULL){
head = p;
return head;
}

node *temp  = head;
while(temp->next != NULL){
    temp = temp->next ;
}
temp->next = p;

return head;
}

void print(node *head){
while(head!=NULL){
cout<info<<" ";
head = head->next;
}
return;
}

node append(node head,int index,int n){
node* slow = head;
node* fast = head;

for(int i=1;i<=index;i++){
    fast = fast->next;
}

/*for(int i=1;i<(n-index);i++){
    slow = slow->next;
}*/

node *newhead = fast->next;

while(fast->next != NULL){
    fast = fast->next;
    slow = slow->next;
}

slow->next = NULL;
fast->next = head;

return newhead;
}

int main() {
int n;
cin>>n;
int data;
node *head = NULL;
for(int i=0;i<n;i++){
cin>>data;
head = insertAtTail(head,data);
}
//print(head);
//cout<<endl;
int index;
cin>>index;

print(append(head,index,n));

return 0;

}
i am getting correct in 1 testcases and run error in 3 testcases, please help?

Run error is due to illegal access of the index. When there is error of Index out of Bound then it shows run error. Do check your code again. You may be accesing some index, or some memory location which is not allowed.