title: fgets unpredicted behavior after reading '\n'
body: <p>Trying to code echo server\client in C, based on sockets.
  I can't understand how fgets() works for sure.</p>
  
  <blockquote>
    <p>If a newline is read, it is stored into the buffer. A terminating null
    byte ('\0') is stored after the last character in the buffer.</p>
  </blockquote>
  
  <pre><code> while (fgets(sendline, MAXLINE, stdin) != NULL) {
    sendline[strlen(sendline)-1] = '\0';
    send(sockfd, sendline, strlen(sendline), 0);}
  </code></pre>
  
  <p>But what I get on server:</p>
  
  <pre><code>String received from and resent to the client:1234567890
  
  String received from and resent to the client:abc
  567890
  </code></pre>
  
  <p>as you can see, '\n' char added to second line, and tries to override first, with new line. But on client, I see that buffer have no '\n' while use send().</p>
  
  <p>Hitting ctld+D (EOF) works as expected.</p>
  
  <p>How to prevent this? And send using Enter key?</p>
  
  <p>This picture expain what I mean. And there is no change after comment certain lines of code (for @PCLuddite)
  <a href="https://i.stack.imgur.com/IGoSC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IGoSC.png" alt="enter image description here"></a></p>