I'm trying to count to 20 using linked lists. I have the code written up, with 2 functions. A function that adds the node to the linked list and one that prints the whole thing. however it's in an infinite loop and I have no idea why. 

I tried debugging multiple times and I believe its the add function, possibly the printlist while is never getting to null and therefore its printing endlessly? I think the add function is not implementing the nodes correctly but I'm unsure how to fix.

This is my struct:

```
struct node
{
int number;
struct node *next;
};
typedef struct node NODE;

```

This is main, which calles the function add and passes it i (0-20) along with the list. 

```
int main(){

int i, size=20;
struct node* mylist = malloc(sizeof(struct node));
mylist->number = NULL;
mylist->next = NULL;

for(i=0;i<size;i++){
   mylist = add(mylist,i);
   }   
  printList(mylist);

return 0;
}

```

add function, which takes temp as the data passed, and iter to iterate through the linked list to the end. When I take away the (&& iter->next->number < number) in the while loop, it prints out nothing but with it, it has the infinite loop

```
struct node* add(struct node *first, int number){
  struct node* temp;
  struct node* iter;

  temp= malloc(sizeof(struct node));
  temp->number=number;
  temp->next=NULL;

  if(first==NULL)
    return temp;

  iter=first;
  while(iter->next!=NULL  && iter->next->number < number){
    iter=iter->next;}

  temp->next=iter->next;
  iter->next=temp;

  return first;
}

```

This is the printlist function which I believe is correct, I think the problem lies in the Add node function.

```
struct node* printList(struct node *mylist){

struct node *helpptr;
helpptr = mylist;

while (helpptr != NULL){
 printf("%d", helpptr->number);
 helpptr = helpptr->next;
                      }
 return 0;
}

```

Thank you for your help in advance