如何将一个整数数组复制到另一个

问题描述:

什么是复制一个整数数组的最佳方式?我知道的memcpy()就是做这件事。有没有像的strdup()

What is the best way to duplicate an integer array? I know memcpy() is one way to do it. Is there any function like strdup()?

有没有,而的strdup 不在标准,无论是。你当然可以只写你自己的:

There isn't, and strdup isn't in the standard, either. You can of course just write your own:

int * intdup(int const * src, size_t len)
{
   int * p = malloc(len * sizeof(int));
   memcpy(p, src, len * sizeof(int));
   return p;
}