title: C read call buffering extra character
body: <p>I am trying to read a file and send it over the network:
  below is my code at server for file reading and sending,</p>
  
  <pre><code>while((sent = read(fp, send_buf, BUFSIZE)) &gt; 0)
  {
      write(cssock, send_buf, strlen(send_buf));
      memset(send_buf, 0, BUFSIZE);
  }
  </code></pre>
  
  <p>and I am reading it at client as:</p>
  
  <pre><code>while(readBytes = read(sock, file_data, BUFSIZE) &gt; 0)
  {
          write(fp, file_data, strlen(file_data));
  }
  </code></pre>
  
  <p>file is transferred fine but I am getting an extra character at the end of buffer and my file is written as:</p>
  
  <blockquote>
    <p>hello my name is abcd garbage-char</p>
  </blockquote>
  
  <p>garbage-char is some arbitery character. Any idea why would I get such extra character?</p>
  
  <p>note: I have double checked my file and it has nothing but the string "my name is abcd". No space, no new line. Any help is appreciated.</p>