The strcpy
function always adds the terminator, but strncpy
may not do it in some cases.
And for the second question, yes you need to make sure there is enough memory allocated for the destination. In your example you have not allocated enough memory, and will have a buffer overflow. Remember that strlen
returns the length of the string without counting the terminator. You also have inverted the arguments to strcpy
, the destination is the first argument.