#include <string.h>
void *memcpy( void *to, const void *from, size_t count );
函数从 from 中复制 count 个字符到 to 中,并返回 to 指针。 如果 to 和 from 重叠,则函数行为不确定。
将 src 数组所有字符复制到 dest 数组中,如下:
#include <stdio.h>
#include <string.h>
int main(void)
{
char src[] = "******************************";
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
char *ptr;
printf("destination before memcpy: %s\n", dest);
ptr = memcpy(dest, src, strlen(src));
if (ptr)
{
printf("destination after memcpy: %s\n", dest);
}
else
{
printf("memcpy failed\n");
}
return 0;
}输出结果:
destination before memcpy: abcdefghijlkmnopqrstuvwxyz0123456709 destination after memcpy: ******************************456709