title: C - Inserting new node alphabetically into linked list
body: <p>I have been reading around and I am still having trouble understanding linked lists. My issue is that for some reason when I traverse the list to determine if any structures in the list have the same name or age it deletes the list or when I try to add a new node into the list it is deleted as well. </p>
  
  <p>The list is dynamic so it I'm not going based off any type of count but how many structures the user decides to enter. </p>
  
  <p>Any direction would be appreciated. </p>
  
  <pre><code>int add(char* name, char* genderValueString, char* breed, int age, float weight)
  {
  
  int result;
  int count = 0;
  gender curGen = 1;
  
  
  struct dog *temp = malloc(sizeof(struct dog));
  
  strcpy(temp-&gt;name, name);
  strcpy(temp-&gt;breed, breed);
  temp-&gt;age = age;
  temp-&gt;weight = weight;
  
  if (strcmpi(genderValueString, "male") == 0) {
      curGen = 0;
  }
  temp-&gt;genderValue = curGen;
  
  
  if (list == NULL) {
      temp-&gt;next = list;
      list = temp;
      result = 1;
  }
  
  else {
  
      while (list != NULL) {
          if (strcmpi(list-&gt;name, name) == 0 &amp;&amp; list-&gt;age == age) {
              result = 0;
          }
  
          else {
              result = 1;
          }
  
          list = list-&gt;next;
      }
  
  
      if (result == 1) {
          while (list != NULL) {
  
              if (strcmpi(list-&gt;name, name) &gt; 0 || list-&gt;age &gt; age) {
  
                  struct dog *prev = list;
                  list = temp;
                  list-&gt;next = prev;              
  
              }   
  
              list = list-&gt;next;
          }
  
  
      }
  
  }
  
  
  return result;
  }
  </code></pre>