Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在结构中创建模拟二维动态阵列 struct Level\u Info { 字符**映射; }级别[级别金额]; 对于(int Cnt_1=0;Cnt_1_C_Pointers - Fatal编程技术网

无法在结构中创建模拟二维动态阵列 struct Level\u Info { 字符**映射; }级别[级别金额]; 对于(int Cnt_1=0;Cnt_1

无法在结构中创建模拟二维动态阵列 struct Level\u Info { 字符**映射; }级别[级别金额]; 对于(int Cnt_1=0;Cnt_1,c,pointers,C,Pointers,GCC说:在第10行的「*」标记之前需要标识符,那么如何修复它呢?替换 struct Level_Info { char **Map; } Level[Level_Amount]; for (int Cnt_1 = 0; Cnt_1 < Level_Amount; Cnt_1++) { Level[Cnt_1].Map = malloc(Rbn_Col * sizeof(char*)); for (int Cnt_2 = 0; Cnt_2 < Rbn_Col; Cnt_

GCC说:
在第10行的「*」标记之前需要标识符,那么如何修复它呢?

替换

struct Level_Info
{
  char **Map;
} Level[Level_Amount];

for (int Cnt_1 = 0; Cnt_1 < Level_Amount; Cnt_1++)
{
  Level[Cnt_1].Map = malloc(Rbn_Col * sizeof(char*));
  for (int Cnt_2 = 0; Cnt_2 < Rbn_Col; Cnt_2++)
    Level[Cnt_1].*(Map+Cnt_2) = malloc(Rbn_Row * sizeof(char)); /* line 10 */
}

或者干脆

*(Level[Cnt_1].Map+Cnt_2) = malloc(Rbn_Row * sizeof(char));
由于
sizeof(char)
by definition总是1,您也可以这样做

Level[Cnt_1].Map[Cnt_2] = malloc(Rbn_Row * sizeof(char));
或者在
Map
点做什么方面保持灵活性

Level[Cnt_1].Map[Cnt_2] = malloc(Rbn_Row);

此外,请注意,索引数组的首选类型是
size\u t
,而不是
int

因此,您的代码片段应该如下所示:

Level[Cnt_1].Map[Cnt_2] = malloc(Rbn_Row * sizeof(Level[Cnt_1].Map[Cnt_2][0]));
struct Level\u Info
{
字符**映射;
}级别[级别金额];
对于(尺寸Cnt Cnt_1=0;Cnt_1
更换

struct Level_Info
{
  char **Map;
} Level[Level_Amount];

for (int Cnt_1 = 0; Cnt_1 < Level_Amount; Cnt_1++)
{
  Level[Cnt_1].Map = malloc(Rbn_Col * sizeof(char*));
  for (int Cnt_2 = 0; Cnt_2 < Rbn_Col; Cnt_2++)
    Level[Cnt_1].*(Map+Cnt_2) = malloc(Rbn_Row * sizeof(char)); /* line 10 */
}

或者干脆

*(Level[Cnt_1].Map+Cnt_2) = malloc(Rbn_Row * sizeof(char));
由于
sizeof(char)
by definition总是1,您也可以这样做

Level[Cnt_1].Map[Cnt_2] = malloc(Rbn_Row * sizeof(char));
或者在
Map
点做什么方面保持灵活性

Level[Cnt_1].Map[Cnt_2] = malloc(Rbn_Row);

此外,请注意,索引数组的首选类型是
size\u t
,而不是
int

因此,您的代码片段应该如下所示:

Level[Cnt_1].Map[Cnt_2] = malloc(Rbn_Row * sizeof(Level[Cnt_1].Map[Cnt_2][0]));
struct Level\u Info
{
字符**映射;
}级别[级别金额];
对于(尺寸Cnt Cnt_1=0;Cnt_1
不带行号的代码段使想要复制/编辑代码并将其提供给编译器更容易。不带行号的代码段使想要复制/编辑代码并将其提供给编译器更容易。