CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2002
    Posts
    65

    memset to null a buffer

    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.

  2. #2
    Join Date
    May 2000
    Location
    Washington DC, USA
    Posts
    715
    char buffer[1024];

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

  3. #3

    Cool

    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);
    }

  4. #4
    Join Date
    Jun 2002
    Location
    New Delhi
    Posts
    6
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured