Lets just take a look at this code:
ptr=n*(malloc(sizeof(n));
ptr=head;
scanf("%d",&ptr->data);
head=ptr->data;
ptr=ptr->next;
You don't need line 1 because you just set it to point to a space of memory that has already been allocated ( head=n*(malloc(sizeof(n));
). Lines 2 and 3 look alright to me. Line 4 doesn't work (I sure hope that doesn't compile) because head is a pointer (to a struct node) and you are trying to assign to it a plain old integer. Since ptr and head point to the same thing, line 3 takes care of what you want. Line 5 may seem to make sense, but it actually does nothing. At the end of this function call, ptr will be deleted. A few final notes: the first time you call this function, it will only allocate memory, not load any data. And you seem to be missing a closing } for the function.