strcpy vs. memcpy

后端 未结 9 858
梦如初夏
梦如初夏 2020-12-07 08:17

What is the difference between memcpy() and strcpy()? I tried to find it with the help of a program but both are giving the same output.

         


        
9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 08:30

    The problem with your test-program is, that the printf() stops inserting the argument into %s, when it encounters a null-termination \0. So in your output you probably have not noticed, that memcpy() copied the characters c and h as well.

    I have seen in GNU glibc-2.24, that (for x86) strcpy() just calls memcpy(dest, src, strlen(src) + 1).

提交回复
热议问题