Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   memset function (http://www.go4expert.com/forums/memset-function-t7905/)

answerme 18Dec2007 12:35

memset function
 
hye can anyone give me the example of memset function

shabbir 18Dec2007 18:10

Re: memset function
 
Code:

TCHAR szPath[MAX_PATH];
memset(szPath,'\0',MAX_PATH);

It will have all the memory location of szPath filled with '\0'

Salem 18Dec2007 19:45

Re: memset function
 
> 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.


All times are GMT +5.5. The time now is 10:52.