title: Function that reads a string from a file of unknown length
body: <p>I've been trying to piece together a function that allows me to create a string out of a given file of unknown length.</p>
  
  <p>What it's <em>supposed</em> to do, is set the size of the output string to a single character, then for each character besides EOF, increment the size of the string by 1 and add the newly read character to it.</p>
  
  <pre><code>void readstring(FILE *f, char *s[])
  {
      int size = 1;
      int c = 0, i = 0;
  
      s = malloc(size*sizeof(char));
  
      while(c != -1)
      {
          c = fgetc(f);
          s[i] = (char)c;
          i++;
  
          if(i == size)
          {
              size++;
              s = realloc(s, size*sizeof(char));
          }
      }
  
      s[i] = '\0';
  }
  
  int main()
  {
      char *in = malloc(2*sizeof(char));
      FILE *IN;
  
      IN = fopen("in.txt", "r");
  
      readstring(IN, in);
  
      printf("%s",&amp;in);
  
      fclose(IN);
      free(in);
  
      return 0;
  }
  </code></pre>