1.memcpy: (不是copy)!!!
#include <stdio.h>
#include <string.h>
struct {
char name[20];
int age;
}person, person_copy;//放在花括号与分号之间
int main()
{
char* my_name = "lijian";//为什么要*才能成功编译?
memcpy(person.name, my_name, sizeof(my_name));
//将my_name的sizeof个字节数传到person.name中
person.age = 21;
printf("%s,%d\n", person.name, person.age);
return 0;
}
2.memmove : *适合于惯性思维
#include <stdio.h>
#include <string.h>
int main()
{
char str[] = "ni shi shui bu zhi dao";
memmove(str + 12, str + 15, 7);
printf("%s\n", str);
return 0;
}