title: Socket c bytes received but I can't print the String
body: <p>I use this code to receive a String from a Java server in a C client.</p>
  
  <pre><code>if( recv( to_server_socket, &amp;reply, sizeof( reply ), MSG_WAITALL ) != sizeof( reply ) )
  {
      printf( "socket read failed");
      exit( -1 );
  }
  
  printf( "got reply: %d\n", ntohl( reply ) );
  
  char buf[512];
  ssize_t nbytes=0;
  int byte_count;
  
  byte_count = recv(to_server_socket, buf, sizeof buf, 0);
  printf("recv()'d %d bytes of data in buf\n", byte_count);
  buf[byte_count] = '\0';
  
  printf("String : %s\n",buf);
  </code></pre>
  
  <p>For example, when the Java server sends this String </p>
  
  <blockquote>
    <p>bZzrEcyVEmjmIf</p>
  </blockquote>
  
  <p>I got this result</p>
  
  <blockquote>
    <p>recv()'d 16 bytes of data in buf String :</p>
  </blockquote>
  
  <p>so I received 16 bytes but the </p>
  
  <pre><code>printf("String : %s",buf);
  </code></pre>
  
  <p>don't show me anything.</p>
  
  <p>The server sent this String </p>
  
  <blockquote>
    <p>TYvuDbbKALp3scp</p>
  </blockquote>
  
  <p>I tried this code  </p>
  
  <pre><code>   int i=0;
      while(i&lt;byte_count){
          printf("String : %c\n",buf[i]);
          i++;  recv()'d 17 bytes of data in buf
  </code></pre>
  
  <p>and for result I have</p>
  
  <blockquote>
    <p>String :  String :  String :  String : T String : Y String : v String
    : u String : D String : b String : b String : K String : A String : L
    String : p String : 3 String : s String : c String : p</p>
  </blockquote>