Set the first byte to 0 or use memset for the entire reset buffer "

In C programming, when I try to execute for the first time, I need

TCHAR file_name[1024];
// Use memset or set the first byte to 0?
file_name[0] = 0;
_tcscat(file_name, TEMP_DIRECTORY_PATH);
_tcscat(file_name, file);

I see that most programmers use memset. But for me, I just set the first byte to 0 so that _tcscat knows where to start.

I'm not sure if there is a flaw / trap for this, instead of using memset?

Thank.

+5
source share
4 answers

You can simply set the first char to 0.

However, it will be even easier

TCHAR file_name[1024];
_tcsncpy(file_name, TEMP_DIRECTORY_PATH, 1024);
_tcscat(file_name, file);
+3
source

, , , , 0 . / , - , ( , , , ).

strcpy(), , , strcat() ` ( , 1- 0).

, "sensitve" ( - ) - , . , http://msdn.microsoft.com/en-us/library/ms972826 , memset() .

+4

, , , null , .. - . , , .

+1

NUL - " " . , , , . , , , , NUL. NUL , "". " ", , , .

, NUL, " " , . NUL - . , . , " " , , , , ....

, , . , .

+1

All Articles