title: inserting node at the end of a linked list in C
body: <p>I am working on a code that inserts a node into the end of a linked list, and simply it does not work. It gives me that same linked list as before, without appending any nodes.</p>
  
  <h3>result</h3>
  
  <pre><code>the old list is :
  9 8 7 6 5 4 3 2 1 0 
  the new list is :
  9 8 7 6 5 4 3 2 1 0 
  </code></pre>
  
  <h3>code</h3>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
  //make a new type structure called node
  typedef struct nodes{
      int n;
      struct nodes* next;
  }node;
  //assigning the first node of the linked list
  node* head=NULL;
  //append function
  void append(int number){
      node* tail=malloc(sizeof(node));
      if(tail==NULL){
          printf("unable to allocate");
          exit(1);
      }
      tail-&gt;n=number;
      tail-&gt;next=NULL;
      if(head-&gt;next==NULL){
          tail-&gt;next=head;
          printf("added successfully");
      }
      else{
          for(node* current=head;current-&gt;next==NULL;current=current-&gt;next){
              current-&gt;next=tail;
              printf("Added successfully");
              break;
          }
      }
  }
  //main function
  int main(int argc,char* argv[]){
      //checking that the commmand is correct
      if(argc!=2){
          printf("Please type ./append and then type the number you want to add to the list");
      }
      //accept numbers in second argument
      int newnumber=atoi(argv[1]);
      //make the list
      for(int i=0;i&lt;10;i++){
          node* newnode=malloc(sizeof(node));
          //checking
          if(new==NULL){
              exit(1);
          }
          newnode-&gt;n=i;
          newnode-&gt;next=head;
          head=newnode;
      }
      //printing the old list
      printf("the old list is :\n");
      for(node* conductor=head;conductor!=NULL;conductor=conductor-&gt;next){
          printf("%i ",conductor-&gt;n);
      }
      //append the number given to the start of the linked list 
      append(newnumber);
      //printing the new list
      printf("\nthe new list is :\n");
      for(node* conductor=head;conductor!=NULL;conductor=conductor-&gt;next){
          printf("%i ",conductor-&gt;n);
      }
      printf("\n");
      return 0;
  }   
  </code></pre>
  
  <p>So the function seems have no impact at all. I can't see where the bug is.</p>