Difference between strncpy and memcpy?

前端 未结 5 1983
粉色の甜心
粉色の甜心 2020-12-05 03:10

How can i access s[7] in s?

I didn\'t observe any difference between strncpy and memcpy. If I want to print the o

5条回答
  •  天涯浪人
    2020-12-05 03:45

    Others have pointed out your null-termination problems. You need to understand null-termination before you understand the difference between memcpy and strncpy.

    The difference is that memcpy will copy all N characters you ask for, while strncpy will copy up to the first null terminator inclusive, or N characters, whichever is fewer. (If it copies less than N characters, it will pad the rest out with null characters.)

提交回复
热议问题