title: Segmentation Fault in a While Loop in C
body: <p>I am just learning c with the cs50 course and I just got introduced to pointers and data structures (It is very confusing please help). So I got a project where I am loading some words from a file into a hash table but I am getting a segmentation fault in while loop, Just at the time of checking the condition and I don't know why is that the case. Someone Please help and Thanks in advance.</p>
  <p>This is the Code I wrote</p>
  <pre><code>bool load(const char *dictionary)
  {
      // Loading the file
      FILE *file = fopen(dictionary, &quot;r&quot;);
      if (file == NULL)
      {
          return false;
      }
  
      // Mallloc space for table
      for (int i = 0; i &lt; N; i++)
      {
          table[i] = malloc(sizeof(node));
      }
  
      // Reading a word and adding to the table until file is empty
      char word [200];
      while (strcmp(word, &quot;EOF&quot;) != 0)
      {
          fscanf(file, &quot;%s&quot;, word);
  
          node *n = malloc(sizeof(node));
          if (n == NULL)
          {
              return false;
          }
          strcpy(n-&gt;word, word);
  
          int index = hash(word);
  
          n-&gt;next = table[index]-&gt;next;
          table[index]-&gt;next = n;
  
          s = s + 1;
  
      }
  
      return true;
  }
  </code></pre>
  <p>These are some of the global variables</p>
  <pre><code>typedef struct node
  {
      char word[LENGTH + 1];
      struct node *next;
  } node;
  
  // TODO: Choose number of buckets in hash table
  const unsigned int N = 30;
  
  // Hash table
  node *table[N];
  
  unsigned int s;
  </code></pre>