Where i'm wrong ? getting a segmentation fault

hi guys; I've tried to write a code whose name factors and this function takes a positive int as an argument and returns a binary tree which consists of the factors of the given int and Left child of any node in the tree should be the smallest int that is greater than 1, not equal to the node and divides the node without remainder. for example :

210

/ \

2 105

/ \

3 35

/ \

5 7

but when ı run my code ı get seg. fault and where ı am wrong ı dont know is there anyone who can help me ?

here is my code :

Code:

`struct node`

{

int value;

struct node *left, *right;

int depth;

};

typedef struct node node;

node* factors(int num){

int i=2;

node * np ;

node ** bas;

bas=(node **)malloc(sizeof(node *));

np=(node *)malloc(sizeof(node));

bas=&np;

np->value=num;

while(i<=(num/2)){

if(num%i==0){

(np->left)->value=i;

(np->right)->value=num/i;

np=(np->right);

}

i+=1;

}

print_tree(np);

return np;

}