title: Searching a linked list recursively in C
body: <p>I'm fairly new to C and I was trying to write a method that will search a linked list recursively, however I had no success. The function contains returns 0 if the name is not found in any of the nodes of the linked list, and 1 is is found.I seem to be getting into an infinite loop. Any help would be greatly appreciated!</p>
  
  <pre><code>#include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  
  struct node
  {
      char name[1000];
      struct node *next;
  };
  
  int contains(const struct node *pNode, const char *name)
  {
      int i;
      int length = strlen(name);
      int isEqual = 0;
  
      while (pNode != NULL)
      {
          isEqual = 1;
          for (i = 0; i &lt; length; i++)
          {
              if (pNode-&gt;name[i] != name[i])
              {
                  isEqual = 0;
              }
          }
      }
  
      contains(pNode-&gt;next, name);
  
      return isEqual;
  }
  
  main()
  {
      struct node node1 = { "Sam", NULL };
      struct node *node1Ptr = &amp;node1;
      struct node node2 = { "Anna", node1Ptr };
      struct node *node2Ptr = &amp;node2;
      struct node node3 = { "Adam", node2Ptr };
      struct node *node3Ptr = &amp;node3;
  
      int n, k;
  
      // testing for a name that is the list
      n = contains(node3Ptr, "Sam");
      printf("%d\n", n);
      // testing for a name that is not in the list
      k = contains(node3Ptr, "Max");
      printf("%d\n", k);
  }
  </code></pre>