You need to handle the case where the entry that you are adding needs to be at the head of the list. Right now you only add to the head when the list is empty. That is handled by changing the if as follows:
if (head==NULL || value < head->n){
node* first = malloc(sizeof(node));
//error checking
if (first==NULL)
return false;
first->next=head;
first->n=value;
head = first;
t=1;
}
Now that the addition to the beginning of the list is taken care of, the else needs a change to get pre and ptr initialized correctly and the insertion condition needs to be changed as follows:
node* ptr=head->next;
node* pre=head;
//putting new node into list
while(t==0){
//insertion
if (ptr==NULL || value<=ptr->n){
body->next=ptr;
pre->next=body;
t=1;
}
//next node
else if(value>ptr->n){
pre=ptr;
ptr=ptr->next;
}
//If all goes wrong
else
t=9; //breaks loop
}
}