我正在從套接字讀取緩衝區字節,但我不知道如何用長度信息初始化緩衝區數組。用變量初始化緩衝區數組的長度
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);
如果我想使用while循環來接收許多圖像,如何在每個循環結束時刪除'buf'的內容? – askingtoomuch 2013-03-12 11:45:33
@boogiedoll請參閱我的更新回答。 – 2013-03-12 12:18:20
太棒了!謝謝 :) – askingtoomuch 2013-03-12 13:47:41