title: Scanning a list of words into slots in an array
body: <p>So, I'm attempting to scan in a large number of words from a text file and store them in a manner that allows them to be accessible from a single array.</p>
  
  <pre><code>149256
  aahing
  aahs
  aals
  aardvark
  aardvarks
  aardwolf
  aardwolves
  aargh
  aarrgh
  aarrghh
  </code></pre>
  
  <p>I'm scanning these words from a text file in the above format. The number is the total number of words(it's a dictionary, explains the high word count) present in the list, and the words follow a line at a time. I'd like to be able to access each individual word from a dynamically allocated  array i.e. word[0] will contain "aahing". Now I know a simple char array is unable to accomplish this. I first attempted to accomplish this with a multidimensional array in the below code:</p>
  
  <pre><code>main(){
  int numWords,i;
  
  FILE * fp= fopen("dictionary.txt","r");
  
  fscanf(fp,"%d", &amp;numWords);
  
  char* array = malloc(numWords * 20 * sizeof(char)); //word length is always below 20
  
     for(i = 0; i &lt; numWords; i++){
  
           fscanf(fp, "%s", &amp;array[i]);
           //printf("%s \n",&amp;array[i]); used to check the scan
     }
  
  printf("%s \n",&amp;array[0]);
  }
  </code></pre>
  
  <p>*The &amp; infront of the array shouldnt be needed by my understadning, but the program crashes when these are not present, probably a problem with my code. </p>
  
  <p>Now when removing the final printf statement and uncommenting the printf in the loop, the program seems to work as it is meant to. But, if you add the last printf,the program prints the first letter of every single word scanned along with the entirety of the last word. From my understanding this shouldn't be possible as each new word should have been scanned into a different row of the array, but obviously this is not the case. In this instance would I be better of somehow assigning each slot of an array to point towards a new array in each slot? i.e. array[1] -> data[] , array[2] -> data[] each of which would contain a new word. 
  A point in the right direction would be greatly appreciated.</p>