[置頂]

書單: 安迪葛洛夫:Only paranoid survives.

Jun 19, 2008

strncpy_s

You are very familiar with strncpy_s(wszStringBuffer, BUFFER_SIZE, wszSourceBuffer, dwCopyBytes)
 
But if you declare wszStringBuffer[16], and call
 
strncpy_s( wszStringBuffer[5], ???, wszSourceBuffer, dwCopyBytes)
 
What value of the second parameter you should use?
 
Answer:
 
Finally, I use (BUFFER_SIZE - 5). I didn't investigate the detail.
 
 
 
Additional information,
 
you can use _countof() macro instead of BUFFER_SIZE as your 2nd parameter.
 
 
However, you can not use pointer in _countof() macro.
 
The following usages are illegal:
 
_countof ( pPointerToArray )
 
_countof ( wszStringBuffer[5] )
 
 
----
Frank

No comments: