这两个经常使用的函数,主要区别有:
- strcpy 返回值是char *, strcpy(x1, x2); x1 x2必须都是char*类型
- memcpy(x1, x2, sizeof(xx)); memcpy可以复制的类型很多;
如果你使用一个数组指针,则不能使用strcpy, 只能使用memcpy.
#cat aa.c
#include <stdio.h>
#include <string.h>
int main()
{
    char s1[64] = "hello";
    char (*ps1)[64] = &s1;
    printf("ps1:%s\n", ps1);
    char s2[64];
    char (*ps2)[64] = &s2;
    strcpy(ps2, ps1);
    memcpy(ps2, ps1, sizeof(char[64]));
    printf("s2:%s\n", s2);
    return 0;
}