声明后不能赋值,使用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}
},
};
Link to understand
第二个错误:
对于这个a[i][j][max],一个字符不能分配字符串,所以,
a[i][j][max] = '0' ; // is correct expression
但是
a[i][j][max] = "0"; // is not correct, wrong
请阅读WhozCraig comment。您正在堆栈中声明巨大的内存!
根据your comment:
函数声明:
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 );