如何将一个整数数组复制到另一个 [英] How to copy one integer array to another

查看:1474
本文介绍了如何将一个整数数组复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是复制一个整数数组的最佳方式?我知道的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;
}

这篇关于如何将一个整数数组复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆