我正在从套接字读取缓冲区字节,但我不知道如何使用长度信息初始化缓冲区数组。
uint32_t len;
int lengthbytes = 0;
int databytes = 0;
// receive the length info of an image data
lengthbytes = recv(clientSocket, (char *)&len, sizeof(len), 0);
// convert hexadecimal data to length in bytes
len = ntohl(len);
// ????? how to initialize the buffer array with the length info ????
char buf[len]; -----> this is illegal in C
// read the image data
databytes = recv(clientSocket, buf, sizeof(buf), 0);