title: About socket recv and char[] in C++
body: <p>I am creating a program that can get package and print it to console by C++.
  I set the char array to 1024 like :</p>
  
  <pre><code>char* buffer = new char[1024];
  </code></pre>
  
  <p>When I get a message is not exactly 1024 character, there is many unknown character on the end of my message because of the empty space in the array. What can I do?</p>
  
  <p>More information (I dont know if it is useful)</p>
  
  <p>The socket is sent by a Java program</p>
  
  <pre><code>Socket socket = new Socket("127.0.0.1", 27555);
  
  BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
  out.write("I am your client :D");
  out.flush(); 
  </code></pre>
  
  <p>And the server is written by C++ console application</p>
  
  <pre><code>char* recvData = new char[1024];
  recv(socket, recvData, strlen(recvData), 0);
  cout &lt;&lt; recvData &lt;&lt; endl;
  </code></pre>