title: How can I reduce code repetition in my C code (unsure due to null pointers)
body: <p>In my project I have linked links of <code>struct elem</code> and each elem has many different attributes.</p>
  
  <p>Currently each time I want to get an elems attribute, I call a function such as:</p>
  
  <pre><code>     get_elem_address(&amp;linked_list);
       get_elem_this(&amp;linked_list);
       get_elem_that(&amp;linked_list);
  </code></pre>
  
  <p>In each function I have the same bit of code:</p>
  
  <pre><code>struct elem *elem = linked_list-&gt;first_elem;
  
  while (elem != NULL) {
      if (elem-&gt;identifer == identifer) get_elem_whatever_i_need;
      elem = elm-&gt;next;
  }
  </code></pre>
  
  <p>In some functions I can guarenteee that there will be an element where the identifers match, in other functions I am not sure. Is there a way I can write a function that will go through the linked list and find the element I want and then return it. </p>
  
  <p>The reason why I am not sure if i can do this is because of the cases where it may not an elem that has the same identifer as the passed in one.</p>