如何字符的3D数组传递给函数 [英] How to pass 3D array of chars to a function
问题描述
我有字符表[] [] []的三维数组,我想将它传递给一个void函数,因此它可以进行更改。我怎样才能做到这一点?
无效化妆(字符轻微[] [] []);.....
烧焦更大[20] [30] [50];
使(较大);
我想这是不是要去工作。
编辑:与此连接的另一个问题是:说我想要做一个复制功能将一个字符串复制到阵列 - 我应该怎么称呼在功能上的strcpy
? 无效复印件(CHAR(*未成年人)[] []){CHAR米[50] =asdasdasd;
的strcpy(次要[] [],M);
}
如果你想传递的阵列的,就像那一个,而不是一个你动态地<$ C分配$ C>的malloc (这将是指针的几级,不是真正的数组),任何下列函数原型将工作:
-
无效化妆(字符未成年人[20] [30] [50])
-
无效化妆(字符轻微[] [30] [50])
-
无效化妆(CHAR(*未成年人)[30] [50])
的原因是你不能拥有像无效化妆(CHAR ***未成年人)
是因为轻微
只会衰变成一个指针数组的数组,它不会腐烂不止一次这么多说了。
I have a 3D array of chars table[][][] and I want to pass it to a void function so it can make changes to it. How can I do this?
void make(char minor[][][]);
.....
char greater[20][30][50];
make(greater);
I guess this is not gonna work.
EDIT: Another question connected with this: Say I want to make a copy function to copy a string into the array - how should I call the strcpy in the function?
void copy(char (*minor)[][])
{ char m[50] = "asdasdasd";
strcpy(minor[][],m);
}
If you wanted to pass an array, just like that one, as opposed to one you've dynamically allocated with malloc
(which would be a few levels of pointers, not real arrays), any of the below function prototypes will work:
void make(char minor[20][30][50])
void make(char minor[][30][50])
void make(char (*minor)[30][50])
The reason being you can't have something like void make(char ***minor)
is because minor
will only decay into a pointer to an array of arrays, it won't decay more than once so to say.
这篇关于如何字符的3D数组传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!