title: Difference between fgets and fread
body: <p>I have the following code below:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main(void)
  {
      int lendata;
      printf(&quot;Content-type:text/html\n\n&quot;);
      printf(&quot;&lt;html&gt;&lt;body&gt;&quot;);
  
      lendata = atoi(getenv(&quot;CONTENT_LENGTH&quot;));
      char *buf = malloc(lendata+1);
      fread(buf,lendata,1,stdin);
  
      printf(&quot;%s\n&lt;br&gt;&quot;,buf); 
      printf(&quot;%d&quot;,lendata);   
  
      free(buf);
  
      printf(&quot;&lt;/body&gt;&lt;/html&gt;&quot;);
      return 0;
  }
  </code></pre>
  <p>When I use <code>fgets</code>, it truncates the data displayed. But when I use <code>fread</code> , it displays all the content. By the way, this is the CGI script for an html file upload using post method. Any help would be greatly appreciated.</p>