title: My program of speller.c is not compiling pset5
body: <p>When I run my program i get these 2 errors and not sure why</p>
  <p>The error</p>
  <pre><code>dictionary.c:87:9: error: use of undeclared identifier 'words_counter'
          words_counter++;
          ^
  dictionary.c:97:12: error: use of undeclared identifier 'words_counter'
      return words_counter;
             ^
  2 errors generated.
  make: *** [Makefile:3: speller] Error 1
  </code></pre>
  <p>The code</p>
  <pre><code>// Implements a dictionary's functionality
  
  #include &lt;stdbool.h&gt;
  
  #include &quot;dictionary.h&quot;
  #include &lt;stdlib.h&gt;
  #include &lt;strings.h&gt;
  #include &lt;cs50.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;string.h&gt;
  
  
  // Represents a node in a hash table
  typedef struct node
  {
      char word[LENGTH + 1];
      struct node *next;
  }
  node;
  
  // Number of buckets in hash table
  const unsigned int N = 1500;
  
  // Hash table
  node *table[N];
  
  // Returns true if word is in dictionary, else false
  bool check(const char *word)
  {
      // TODO
      int index = hash(word);
      node *cursor = table[index];
      while (cursor != NULL)
      {
          if (strcasecmp(word, cursor -&gt; word) ==0 )
          {
              return true;
          }
          //Move cursor to next node
          cursor = cursor -&gt; next;
      }
      return false;
  }
  
  // Hashes word to a number
  unsigned int hash(const char *word)
  {
      // TODO
      // Ref of hash function: https://cs50.stackexchange.com/questions/38753/cs50-good-hash-function-for-pset5-speller/38755
      int hash = 600;
      while (*word != '\0')
      {
          hash = ((hash &lt;&lt; 4 ) + (int) (*word)) % N;
          word++;
      }
      return hash % N;
  }
  
  // Loads dictionary into memory, returning true if successful, else false
  bool load(const char *dictionary)
  {
      // TODO
      FILE *file = fopen(dictionary, &quot;r&quot;);
      if (file == NULL)
      {
          return false;
      }
      // Read strings from file
      // define word
      char word [LENGTH + 1];
      int index;
      while(fscanf(file, &quot;%s&quot;, word) != EOF)
      {
          // Creating new node
          node *n = malloc(sizeof(node));
          if (n == NULL)
          {
              return false;
          }
          // Copies word to the node
          strcpy (n-&gt;word, word);
          // Obtaining index to hash word
          index = hash(word);
          n -&gt; next = table[index];
          table[index] = n;
          words_counter++;
      }
      fclose(file);
      return true;
  }
  
  // Returns number of words in dictionary if loaded, else 0 if not yet loaded
  unsigned int size(void)
  {
      // TODO
      return words_counter;
  }
  
  // Unloads dictionary from memory, returning true if successful, else false
  bool unload(void)
  {
      // TODO
      //Free nodes in each linked list
      for (int i = 0; i&lt;N; i++)
      {
          node *cursor = table[i];
          node *tmp = cursor;
          while (cursor != NULL)
          {
              cursor = cursor-&gt; next;
              free (tmp);
              tmp = cursor;
          }
      }
      return true;
  }
  </code></pre>
  <p>I defined words_counter and it compiled but it seems I did not pass check50 by 2 mistakes:
  the code</p>
  <pre><code>// Implements a dictionary's functionality
  
  #include &lt;stdbool.h&gt;
  
  #include &quot;dictionary.h&quot;
  #include &lt;stdlib.h&gt;
  #include &lt;strings.h&gt;
  #include &lt;cs50.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;string.h&gt;
  
  
  // Represents a node in a hash table
  typedef struct node
  {
      char word[LENGTH + 1];
      struct node *next;
  }
  node;
  
  // Number of buckets in hash table
  const unsigned int N = 1500;
  unsigned words_counter;
  
  // Hash table
  node *table[N];
  
  // Returns true if word is in dictionary, else false
  bool check(const char *word)
  {
      // TODO
      int index = hash(word);
      node *cursor = table[index];
      while (cursor != NULL)
      {
          if (strcasecmp(word, cursor -&gt; word) == 0 )
          {
              return true;
          }
          //Move cursor to next node
          cursor = cursor -&gt; next;
      }
      return false;
  }
  
  // Hashes word to a number
  unsigned int hash(const char *word)
  {
      // TODO
      // Ref of hash function: https://cs50.stackexchange.com/questions/38753/cs50-good-hash-function-for-pset5-speller/38755
      int hash = 600;
      while (*word != '\0')
      {
          hash = ((hash &lt;&lt; 4 ) + (int) (*word)) % N;
          word++;
      }
      return hash % N;
  }
  
  // Loads dictionary into memory, returning true if successful, else false
  bool load(const char *dictionary)
  {
      // TODO
      FILE *file = fopen(dictionary, &quot;r&quot;);
      if (file == NULL)
      {
          return false;
      }
      // Read strings from file
      // define word
      char word [LENGTH + 1];
      int index;
      while(fscanf(file, &quot;%s&quot;, word) != EOF)
      {
          // Creating new node
          node *n = malloc(sizeof(node));
          if (n == NULL)
          {
              return false;
          }
          // Copies word to the node
          strcpy (n-&gt;word, word);
          // Obtaining index to hash word
          index = hash(word);
          n -&gt; next = table[index];
          table[index] = n;
          words_counter++;
      }
      fclose(file);
      return true;
  }
  
  // Returns number of words in dictionary if loaded, else 0 if not yet loaded
  unsigned int size(void)
  {
      // TODO
      return words_counter;
  }
  
  // Unloads dictionary from memory, returning true if successful, else false
  bool unload(void)
  {
      // TODO
      //Free nodes in each linked list
      for (int i = 0; i&lt;N; i++)
      {
          node *cursor = table[i];
          node *tmp = cursor;
          while (cursor != NULL)
          {
              cursor = cursor-&gt; next;
              free (tmp);
              tmp = cursor;
  
  
          }
      }
      return true;
  }
  </code></pre>
  <p>the mistakes:</p>
  <p>:) dictionary.c exists</p>
  <p>:) speller compiles</p>
  <p>:( handles most basic words properly</p>
  <p>expected &quot;MISSPELLED WOR...&quot;, not &quot;MISSPELLED WOR...&quot;</p>
  <p>:) handles min length (1-char) words</p>
  <p>:) handles max length (45-char) words</p>
  <p>:) handles words with apostrophes properly</p>
  <p>:( spell-checking is case-insensitive</p>
  <p>expected &quot;MISSPELLED WOR...&quot;, not &quot;MISSPELLED WOR...&quot;</p>
  <p>:) handles substrings properly</p>
  <p>:) program is free of memory errors</p>
  <p>I am not sure how to handle these 2</p>