title: Search linked list with two pointers
body: <p>I'm currently writing a task for uni trying read in a data from either a file or stdin, tokenising allt the words and presenting a list of occurring words and the count of each word. </p>
  
  <p>Example of desired output:</p>
  
  <pre><code>Good bye occurred 5 times
  This occurred 3 times
  Hello occurred 1 time
  </code></pre>
  
  <p>Example of current output:</p>
  
  <pre><code>This
  1
  is
  1
  fun!
  
  1
  This
  1
  is
  1
  fun!
  </code></pre>
  
  <p>Don't mind the formatting of the output. That is an issue to be fixed later. </p>
  
  <p>I have a running program that uses a linked list declared as follows:</p>
  
  <pre><code>typedef struct node
  {
      char word[50];
      int count;
      struct node * next;
  }words;
  </code></pre>
  
  <p>The linked list is initialised as follows</p>
  
  <pre><code>words * head = NULL;
  head = malloc(sizeof(words));
  </code></pre>
  
  <p>And two pointers assigned to the list</p>
  
  <pre><code>words * current = head;
  words * search = head;
  </code></pre>
  
  <p>What I'm struggling with is the following piece of code:</p>
  
  <pre><code>while (!feof(input_file))
  {
      while(current-&gt;next != NULL)
      {
          current = current-&gt; next;
      }
  
      //Test-loop for tokenisation
      while(fgets(buffer,512, input_file) != NULL)
      {
          //Declaration of char token
          char* token;
  
          //Declaration of flag
          int duplicate_word = 1;
          //Test for-loop
          for (token = strtok(buffer, " "); token != NULL; token = strtok(NULL, " "))
          {
              char duplication_check_token[60];
              strcpy(duplication_check_token, token);
  
              while(search != NULL)
              {
                  char duplication_check_search[60];
                  strcpy(duplication_check_search, current -&gt; word);
                  if (strcmp(duplication_check_search, duplication_check_token) == 0)
                  {
                      search-&gt;count++;
                      duplicate_word = 0;
                      break;
                  }
                  search = search -&gt; next;
              }
  
              if (duplicate_word != 0)
              {
                  while(current-&gt;next != NULL)
                  {
                      current = current-&gt; next;
  
                  }
  
                  current = malloc(sizeof(words));
                  strcpy(current -&gt; word, token);
                  current -&gt; count = 1;
                  current -&gt; next = NULL;
  
                  //Test print
                  printf("%s\n", token);
                  printf("%d\n", current -&gt; count);
              }
  
          }
  
  
  
      }
  </code></pre>
  
  <p>When debugging, it never seems to check through the entire linked list in the <code>while(search != NULL)</code>loop.</p>
  
  <p>What part of the logic am I getting wrong? </p>
  
  <p>Thank you for any help!</p>