1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

memset function

Discussion in 'C' started by answerme, Dec 18, 2007.

  1. answerme

    answerme New Member

    Joined:
    Dec 17, 2007
    Messages:
    114
    Likes Received:
    0
    Trophy Points:
    0
    hye can anyone give me the example of memset function
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Code:
    TCHAR szPath[MAX_PATH];
    memset(szPath,'\0',MAX_PATH);
    It will have all the memory location of szPath filled with '\0'
     
  3. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    > memset(szPath,'\0',MAX_PATH);
    And if TCHAR isn't a char, then you'll need one of
    Code:
    memset(szPath,'\0',MAX_PATH * sizeof TCHAR );
    memset(szPath,'\0',MAX_PATH * sizeof szPath[0] );
    memset(szPath,'\0',sizeof szPath );
    http://c-faq.com/malloc/calloc.html
    Focus on the bit about "all-bits-zero". In other words, don't rely on memset giving you valid floats or pointers, if you try the same approach on attempting to clear more complex data types.
     

Share This Page