title: Creating an array of chars to accept a message from a client on a server
body: <p>I am trying to write a program in C++ that will accept a message from a client on a server. But first of all the client sends the <strong>size</strong> of the message and using this value the server will create an array of chars to store the message when it is finally sent. When I try to initialise the array using the message size value the compiler says that there is an error as the messageSize integer must be a constant value - I was wondering why this is happening, because as far as I understand it is quite acceptable to initialise the length of an array with an integer type:</p>
  
  <pre><code>//Deal with data in DNS style
  int dnsStyle()
  {   
      recv(clientSocket, bufferSize, 1, MSG_WAITALL);
      return bufferSize[0];
  }
  
  //Communicate in the DNS style of addressing
  char DNS()
  {
      int messageSize = dnsStyle();
      printf("The message buffer has been tailoured to this size: '%d'", messageSize);
      char bufferMessDNS[messageSize];
      //Then recieve the actual message itself
      recv(clientSocket, bufferMessDNS, messageSize, MSG_WAITALL);
      //Then send the message back to client
      send(clientSocket, bufferMessDNS, messageSize, 0);
  
      //std::string returnMess = "OK";
      //send(clientSocket, sendBack.c_str(), sendBack.size(),0);
  }
  </code></pre>