title: Linked lists with strings
body: <p>I'm trying to create a program that begins by parsing a number of strings and adding them into a Linked List, and then ending by printing out the occurrences of each string. </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;stdbool.h&gt;
  typedef struct Node Node;
  
  struct Node
  {
      char* word;
      int count;
      struct Node *next;
  };
  
  Node *head = NULL;
  Node *curr = NULL;
  
  Node* listAdd(char* word, bool toEnd) {
      Node* tmp = head;
      while (tmp) {
          if (strcmp(tmp, word) == 0) {
              tmp-&gt;count++;
              return tmp;
          }
          tmp = tmp-&gt;next;
      }
      printf("allocate memory for node");
      Node *ptr = malloc(sizeof(Node));
  
      printf("initialize count to 0");
      ptr-&gt;count = 0;
  
      printf("allocate memory to hold word");
      ptr-&gt;word = malloc(strlen(word) + 1);
  
      printf("copy the current word");
      strcpy(ptr-&gt;word, word);
  
      ptr-&gt;next = NULL;
  
      if (toEnd)
      {
          curr-&gt;next = ptr;
          curr = ptr;
      }
      else
      {
          ptr-&gt;next = head;
          head = ptr;
      }
      return ptr;
  }
  
  void printList()
  {
      Node *ptr = head;
      while (ptr)
      {
          printf("\nThe word [%s] has had [%d] occurrences.\n",ptr-&gt;word, ptr-&gt;count);
          ptr = ptr-&gt;next;
      }
  }
  
  char* readWord()
  {
      static char buffer[100];
      scanf("%s", buffer);
      printf("listAdd() call");
      listAdd(buffer);
      return buffer;
  }
  
  int main(void)
  {
      int i = 0;
      printf("How many words would you like to type?\n");
      scanf("%d", &amp;i);
      for (i; i != 0; i--)
      {
          readWord();
      }
      printList();
  }
  </code></pre>
  
  <p>Current output:</p>
  
  <pre><code>How many words would you like to input?
  3
  hi
  bye
  yes
  How many words would you like to input?
  Occurrences: 12086064
  </code></pre>
  
  <p>Any assistance would be greatly appreciated — I'm still a novice at C coming from C# :(</p>