Since you say you are writing a 'c-style' program, I'll presume that 'node' is some kind of pre-defined structure, elsewhere declared, above the 'insert' function you have provided, or is added in an include file, in the first several lines of code, in the document that holds this function.
The lower case 'insert' is generic enough to be flagged as an issue, as a pre-declared-machine-function. The '*ptr' is another issue all together, as the '*' is code for 'pointer to' 'ptr', which is an abbreviation for the word 'pointer'.
Depending on how the English of the Code is Compiled by the machine Co-Processor, results may vary. The machine is very strict.
You Wrote:
void insert(node *ptr,int data,int key)
{
node *prev;
ptr=ptr->next;
while((ptr->key)<key)
{
prev=ptr;
ptr=ptr->next;
}
node *nw;
nw=(node*)malloc(sizeof(node));
nw->info=data;
nw->key=key;
nw->next=ptr;
prev->next=nw;
}
When inserting new data to replace old data in a more 'main' function body, and modifying its variables and structure containers, your input function members: node, data, key, prev, next; may be already 'key' words within the compiler and 'C' language, are also what you bring into the function body, the information for each of these members, must fully comply both in type and structure, within the code of the called function above and elsewhere within the code in the main code calling this particular insert function. Syntax structure compliance is mandatory.
The above code is commented below:
void insert(node* ptr, int data, int key)
{
node* ptr_node = main_current_node;
main_current_node = main_next_node;
while((main_current_node->key) < key)
{
ptr_node = main_current_node;
main_current_node = main_next_node; }
node* nw;
nw = (node*)malloc(sizeof(node));
prev = new node();
nw->info = data;
nw->key = key;
nw->next = ptr->next;
prev->next = nw;
main_next_node = nw;
}
This a first rough try at a repair. Any way the code you wrote is a bit ambiguous.