本文介绍了如何清除C中的缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个接收器缓冲区,我在其中接收来自recv()的数据;打电话给我想从recv()接收数据后清除缓冲区;调用缓冲区.
I have a receiver buffer in which i am receiving data from the recv(); call i want to clear the buffer after receiving data from the recv(); call in to the buffer.
#define DEFAULT_BUFLEN 512
char recvbuf[DEFAULT_BUFLEN];
int recvbuflen = DEFAULT_BUFLEN;
char common[276];
int main()
{
//After connect and send call...
iResult = recv(ThreadSocket, recvbuf, recvbuflen, 0);
if ( iResult>0 )
{
for(int j=0;j<=iResult;j++)
common[j]=recvbuf[j];
//NOW I WANT TO CLEAR recvbuf.......
//fflush can't be used,how can i do so?
}
请用伪代码告诉
Please tell by pseudo code
推荐答案
memset(recvbuf, 0, sizeof(recvbuf));
会做的.
will do the job.
Tarun Batra写道:
Tarun Batra wrote:
for(int j=0;j<=iResult;j++)
common[j]=recvbuf[j];
正如 Graham Breach 所指出的那样,您将使用此类代码来覆盖common
缓冲区.
As already noted by Graham Breach you are going to overrun the common
buffer with such code.
这篇关于如何清除C中的缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!