求大神解决下C语言问题
下面这段代码中的这行item=*(maze+(i*col_size+j));代码不懂啥意思。怎么就输出一个item就能输出全部行和列了。voidprint_maze(ch...
下面这段代码中的这行item=*(maze+(i*col_size+j));代码不懂啥意思。怎么就输出一个item就能输出全部行和列了。void print_maze(char *maze,int row_size,int col_size){ int i; int j; char item; for(i=0;i<row_size;i++){ for(j=0;j<col_size;j++){ item=*(maze+(i*col_size+j)); printf("%c ",item); } printf("\n"); printf("\n"); }}void main(void){ // 示例迷宫 char maze[9][9]={ {'#','#','#','#','#','#','#','#','#'}, {'#','@','#','#','@','@','@','@','#'}, {'#','@','@','@','@','#','#','#','#'}, {'#','@','#','#','@','@','@','@','#'}, {'#','@','@','@','#','#','#','#','#'}, {'#','#','#','@','@','@','@','@','#'}, {'#','#','#','#','#','@','#','@','#'}, {'#','#','#','#','#','@','#','@','#'}, {'#','#','#','#','#','#','#','#','#'},}; print_maze(&maze[0][0],9,9); }
展开
2个回答
展开全部
#include <stdio.h>
void print_maze(char *maze,int row_size,int col_size)
{
int i; int j;
char item;
for(i=0;i<row_size;i++)
{
for(j=0;j<col_size;j++)
{
item=*(maze+(i*col_size+j)); //这是查二维数组 的代码
//maze 数组的起始地址
printf("%c ",item);
}
printf("\n");
printf("\n");
}
}
int main(void) // 示例迷宫
{
char maze[9][9]=
{
{'#','#','#','#','#','#','#','#','#'},
{'#','@','#','#','@','@','@','@','#'},
{'#','@','@','@','@','#','#','#','#'},
{'#','@','#','#','@','@','@','@','#'},
{'#','@','@','@','#','#','#','#','#'},
{'#','#','#','@','@','@','@','@','#'},
{'#','#','#','#','#','@','#','@','#'},
{'#','#','#','#','#','@','#','@','#'},
{'#','#','#','#','#','#','#','#','#'},
};
print_maze(&maze[0][0],9,9);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询