title: C finding the last element of the list passed as a argument
body: <p>I have a global list</p>
  
  <pre><code>typedef struct center {
    char center_name[100];
    char hostname[100];
    int port;
  
    struct center *next_center;
  } center;
  </code></pre>
  
  <p>So when i start:</p>
  
  <pre><code>int main(int argc, char** argv) {
    center *head = null;
    parse(argv, &amp;head);
  }
  </code></pre>
  
  <p>where parse:</p>
  
  <pre><code> void parser (char** argv, center **head) {
     //read a file amd add the elements to a newCenter
     addToCenterList(newcenter, head);
   }
  </code></pre>
  
  <p>where addToCenterList:</p>
  
  <pre><code>void addToCenterList(center *newcenter, center **head) {
    center *newNode = malloc(sizeof(center));
    strcpy(newNode-&gt;center_name, newcenter-&gt;center_name);                
    strcpy(newNode-&gt;hostname, newcenter-&gt;hostname);
    newNode-&gt;port = newcenter-&gt;port;
    newcenter-&gt;next_center = NULL;    
  
    if (*head == NULL)       
      *head = newNode; 
    else {
      //problem starts here, it never adds after the first element
      center **iterator; 
      center ite; 
      iterator = head; 
      ite = **iterator;
  
      while(1){
        if(ite.next_center == NULL){
          *ite.next_center = *newNode; 
          break; 
        }                  
      }
  }
  </code></pre>
  
  <p>My problem starts with the else:
  I am passing the address of the head of the list.
  So I know i need a variable that allows to move through the list. 
  I have tried many things and none work. 
  I had in mind: iterate through the list and store the address of each "node" in some variable, and if the content of that address (the node!) its the next_center is == NULL then i would stop looking since that is the last element.
  And afterward i would just assign that next_center address a new content. </p>
  
  <p>Thats what i am trying to do. I dont know how to make it work....</p>
  
  <p>thanks in advance. </p>