声明后你不能分配,但使用strcpy()
char a[250][250][250];
strcpy(a[0][1],"0");
或在声明时指定:
char a[250][250][250] = {"0","2"};
char a[][250][250] = {"0","2"};
或者如果你想分配一个字符。
a[i][j][k] = '0';
其中 i、j、k 是小于 250 的任何值
如何在 C 中声明和初始化 3D 数组
通常a[3][4][2]
是一个三维数组,可以看作
a[3][4][2]
:由3 个二维数组组成,其中每个二维数组由 4 行和 2 列组成。可以声明为:
char a[3][4][2] = {
{ //oth 2-D array
{"0"},
{"1"},
{"2"},
{"4"}
},
{ //1th 2-D Array
{"0"},
{"1"},
{"2"},
{"4"}
},
{ //2nd 2-D array
{"0"},
{"1"},
{"2"},
{"4"}
},
};
注意:“1”表示两个字符,另外一个来自 null ('\0') 字符。
如果是整数数组:
int a[3][2][3]=
{
{ //oth 2-D array, consists of 2-rows and 3-cols
{11, 12, 13},
{17, 18, 19}
},
{//1th 2-D array, consists of 2-rows and 3-cols
{21, 22, 23},
{27, 28, 29}
},
{//2th 2-D array, consists of 2-rows and 3-cols
{31, 32, 33},
{37, 38, 39}
},
};
链接了解
第二个错误:
对此,a[i][j][max]
一个字符不能分配字符串,所以,
a[i][j][max] = '0' ; // is correct expression
但
a[i][j][max] = "0"; // is not correct, wrong
请阅读WhozCraig 评论。您正在堆栈中声明巨大的内存!
根据您的评论:
函数声明:
char add_func(char a[250][250][250], int i, int j); // function definition
试试这样:
char a[250][250][250];
a[i][j][max] = add_func(a, i, j );