title: Reading each line of file into array
body: <p>I'm reading a file and want to put each line into a string in an array. The length of the file is arbitrary and the length of each line is arbitrary (albeit assume it will be less than 100 characters).</p>
  
  <p>Here's what I've got and it's not compiling. Essentially this is an array to an array of characters, right? So shouldn't it be <code>char** words = (**char)malloc(sizeof(*char));</code>?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(){
  
  
   int BUFSIZE = 32767;//max number of lines to read
   char** words = (**char)malloc(sizeof(*char));//gives error: expected expression before 'char'
   FILE *fp = fopen("coll.txt", "r");
   if (fp == 0){
          fprintf(stderr, "Error opening file");
          exit(1);
   }
  
  int i = 0;
  words[i] = malloc(BUFSIZE);
  while(fscanf(fp, "%100s", words[i]) == 1)//no line will be longer than 100
  {
          i++;
          words[i] = realloc(words, sizeof(char*)*i);
   }
  
   int j;
   for(j = 0; j &lt; i; j++)
      printf("%s\n", words);
  
   return 0;
  }
  </code></pre>
  
  <p>Note: I've read "<a href="https://stackoverflow.com/questions/4237084/reading-from-a-file-and-storing-in-array">Reading from a file and storing in array</a>" but it doesn't answer my question.</p>