Click to See Complete Forum and Search --> : memset to null a buffer


billfor
June 17th, 2002, 11:44 AM
I am using a character buffer repeatedly. For example to converti integer numbers to ascii. How do I null out the buffer if I use it over and ove. I know about memset, but I don't know what to copy into the variable using memset. Should I just copy the '\0' character into the first position using memset? Is '\0' the correct
character to fill it with?

So for example char buffer[1024];

How do I null out this buffer using memset.

Thank you for your help.

JMS
June 17th, 2002, 01:26 PM
char buffer[1024];

memset( (void *)&buffer, '\0', sizeof(buffer));

Plastelin
June 18th, 2002, 02:24 AM
The simplest way!

template <class T>
void ZeroMem(T& oData)
{ memset(&oData, 0, sizeof(T));}

void main()
{
struct oRec {...};
oRec Rec;
char szBuff[1024];
ZeroMem(szBuff);
ZeroMem(Rec);
}

littlemutex
June 19th, 2002, 12:27 AM
Hi...the character '\0' and 0 is the same thing... so if u use memsetmemset(buffer, '\0', 1024); or memset(buffer, 0, 1024); ...it actually means the same thing....u can verify this in ur debug window...