title: Trying to read list of words from file and store into an array in C
body: <p>my goal is to read my text file "dictionary.txt" line by line and save all the words in it to my array called words for now and would like to print it to make sure the array contains everything but I'm pretty new to C and not sure how to go about it. The program just crashes when I try to run it and not sure why.
  <br>(it is a rather large text file that contains 149256 words with the longest word being 20 characters)
  <br><br>
  edit: I would like to have the array dynamically allocated, not sure if this is how to do it.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #define listlength 149256
  #define wordslength 21
  
  
  char** getwords(int rows, int col);
  void freeArray(char** words, int rows);
  
  int main(){
  
      int i,j, numCases;
      char** words = getwords(listlength, wordslength);
      //test to see if the words array is saving correctly
  
      for(i=0;i&lt;20;i++){
          printf("%s", words[i]);
      }
  
      //Get number of cases.
      //printf("enter number of cases:\n");
      //scanf("%d", &amp;numCases);
      //Process each case.
  
      freeArray(words, listlength);
  
  }
  
  
  char** getwords(int rows, int col){
  
      //allocate top level of pointers.
  
      char** words = malloc(sizeof(char*)*rows);
      int i;
      FILE *dictionary;
  
      //allocate each individual array
      for(i=0; i&lt;rows; i++){
          words[i] = malloc(sizeof(char)*col);
      }
          //read dictionary.txt
      for(i=0; i&lt;rows; i++){
          FILE *dictionary = fopen("dictionary.txt", "r");
          fgets(words[i],wordslength,dictionary);
      }
  
      fclose(dictionary);
      return words;
  }
  
  void freeArray(char** words, int rows){
  
      int i;
      for(i=0; i&lt;rows; i++){
          free(words[i]);
      }
      free(words);
  }
  </code></pre>