ok, a new problem. inserting a node in a sorted list. I just give the struct and the sortedinput function, as everything works flawlessly.

the problem is in the special case when new is younger than the head node. it always prints as if it is older. if I enter:
Code:
a 10 b 20 c 5
it should print out
Code:
c 5 a 10 b 20
but instead it prints out
Code:
a 10 c 5 b 20

Code:
typedef struct node
	{
		int age;
		char name[10];
		struct node *next;
	} person;


void sortedinput(person **head)
{
	person *new = malloc(sizeof(person));
	person *temp = *head;
	char name[10];
	
	printf("\nEnter name: ");
	scanf("%s", name);
	strcpy(new->name, name);
	printf("Enter age: ");
	scanf("%d",&new->age);
	
	/*special case if list is empty*/
	if (*head == NULL)
	{
		*head = new;
		new->next = NULL;
	}
	else
	{
		/*special case when new is younger than temp(head)*/
		if (new->age < temp->age)
		{
			new->next = temp;
			temp = new;
		}
		else
		/*cases when new is older than temp(head)*/
		{
			while (temp->next != NULL && temp->next->age < new->age)
			{
				temp = temp->next;
			}
			new->next = temp->next;
			temp->next = new;
		}	
	}
}