从2D阵列复制(行)到1D阵列 [英] Copy (row) from 2D array to 1D array

查看:182
本文介绍了从2D阵列复制(行)到1D阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个2d数组多阵列[a] [b]和另一个数组buf [b]。

So I have a 2d array multiarray[a][b] and another array buf[b].

我有麻烦指定'buf'等于多阵列的行中的一行。

I'm having trouble assigning 'buf' to be equal to one of the rows of the multiarray. What is the exact syntax to do this?

推荐答案

// a 2-D array of char
char multiarray[2][5] = { 0 };
// a 1-D array of char, with matching dimension
char buf[5];
// set the contents of buf equal to the contents of the first row of multiarray.
memcpy(buf, multiarray[0], sizeof(buf)); 

这篇关于从2D阵列复制(行)到1D阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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