c memcpy函数

void *memcpy(void *dest, void *src, unsigned n);

string.h

返回值:dest*地址

功能:拷贝src n个字节到dest指向的内存

#include 
#include 
#include 

#define BUFFSIZE 1024
struct {
    char name[50];
    int age;
} zhangsan, wangsi;

int main() {
    char name[20] = "zhangsan";
    memcpy(zhangsan.name, name, strlen(name) + 1);
    zhangsan.age = 18;
    memcpy(&wangsi, &zhangsan, sizeof(zhangsan));

    printf("wangsi.name:%s, wangsi.age:%d\n", wangsi.name, wangsi.age);

    return 0;
}

  

你可能感兴趣的:(c memcpy函数)