I am trying to write a function that inserts numbers(from the user)to nodes (1 number for each node) and then sorts them in an ascending way. I wrote this function:
void insertnode(struct n_node *head)
{
struct n_node *temp = head;
int number;
printf("Please insert a number to the node\n");
scanf("%d", &number);
while (number != SENTRY)
{
while ((temp->next != NULL) && (temp->next->num < number))
{
temp = temp->next;
}
struct n_node *addNode = (struct n_node*)malloc(sizeof(struct n_node));
addNode->num = number;
if (temp->next == NULL && number < temp->num)
{
addNode->next = temp;
head = addNode;
}
else
{
addNode->next = temp->next;
temp->next = addNode;
}
temp = head;
scanf("%d", &number);
}
options();
}
It compiles but right after I insert the first number is stops, gives me a break message and points on this line:
while ((temp->next != NULL) && (temp->next->num < number))
nothing appears on the error list, any help is appreciated, Thanks!