我想检查是否tab[i][j + 1]
存在,它是一个 int **tab;
if (tab[i][j + 1] && tab[i][j + 1] == a_value)
tab[i][j + 1] = 1;
printf("%d\n", tab[i][j + 1]);
它打印我a_value
,但如果我起飞tab[i][j + 1]
if (/*tab[i][j + 1] && */tab[i][j + 1] == a_value)
tab[i][j + 1] = 1;
printf("%d\n", tab[i][j + 1]);
它打印我1
。
为什么我不能检查是否tab[i][j + 1]
存在?
这是我将地图放入数组的位置
while (tmp != 22)
{
ln = read(fd, buff, 22);
buff[ln] = '\0';
while (buff[k] != '\0')
{
if (buff[k] == 'x')
tab[i][j] = WALL;
else if (buff[k] == ' ')
tab[i][j] = 0;
else if (buff[k] == 'e')
tab[i][j] = ENTRE;
else if (buff[k] == 's')
tab[i][j] = SORTIE;
k++;
j++;
}
k = 0;
tab[i][j] = -5;
j = 0;
i++;
tab[i] = malloc(sizeof(*tab) * 2000);
tmp++;
}
这是地图
xxxxxxxxxxxxxxxxxxxxx
xxx s
xxx xxxxxxxxxxxxxxxxx
xxx xxxxxxxxxxxxxxxxx
xxx xxxxx xxxxxxxxxxx
xxx xxxxx xxxxxxxxxxx
xxx xxxxx x
xx xxxxx x xxxxx x
xx xxxxxx xxx xxxxx x
xx xxx xxxxx x
xxxxxxxxx xxx xxxxx x
xxxxxx xxxxx x
xxxxxxxxx xxx xxx x
xxx xxxx xxx x
xxxxx xxx xxxxx xxx x
xxxxx xxx xxxx xxx x
xxx xxxx xxxx xx x
xxxx xxxxx xxxxx xx x
xxxx xxx xxxxx xx x
xxxx xxx xxx
xxxxxxxxexxxxxxxxxxxx