title: C function to read entire file not working
body: <p>I wrote this small program to read an entire file into a <code>char*</code>, which I could then parse more freely than from a file. However, when I run it none of the file seems to get copied into <code>buf</code>, because neither printing the string or the individual chars seems to work.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(int argc, char **argv)
  {
      FILE *fp = fopen("/home/&lt;not shown&gt;/.profile", "r");
      fseek(fp, 0, SEEK_END);
      char *buf = malloc(ftell(fp) + 1);
      fseek(fp, 0, SEEK_SET);
      while ((*buf++ = fgetc(fp)) != EOF) {}
      printf("%s\n", buf);
  }
  </code></pre>
  
  <p>I'm pretty new to c, so could you help me find an answer to this conundrum?  </p>