-1

Please find below code snippet. Is there any chance wherein strncat and memcpy will have different values in pDBVal. If so, Please explain.

memcpy(pDBVal, pHash, 20); 

strncat(pDBVal, cBinSalt, 16);

memcpy(pDBVal+20,cBinSalt,16);

Ideally output in pDBVal will be same. Also please explain the difference in execution of both the functions

chrk
  • 4,037
  • 2
  • 39
  • 47
  • 4
    They are completely different. It looks like you are using trial and error to solve your problem. What are you trying to achieve? – David Heffernan Jul 07 '14 at 08:16
  • Do not use `strXX` functions for binary data. Do not use `memXX` functions for strings. That is the difference. For "explaining the difference in execution", read any [reference](http://en.cppreference.com/w/c/string/byte) [guide](http://en.cppreference.com/w/c/string/byte/memcpy). – Jongware Jul 07 '14 at 08:26

1 Answers1

3

strncat is supposed to be used for string concatenation, so in

strncat(pDBVal, cBinSalt, 16);

If the length of cBinSalt is less than 16, only the content up to '\0' is copied.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294