请求C语言编程高手帮助

来源:百度知道 编辑:UC知道 时间:2024/07/02 06:45:10
#include<stdio.h>
#define ROW 6
#define COL 6
//*************变量及函数声明*******************
typedef struct
{
int x;
int y;
}direction;

direction move[4]={
{1,0},
{-1,0},
{0,-1},
{0,1}};

int findpath(int row,int col);
void print_path();

//4×4迷宫图:
int pic[ROW][COL]={
{1,1,1,1,1,1},
{1,0,0,1,1,1},
{1,1,0,0,0,1},
{1,0,0,1,1,1},
{1,1,0,0,0,1},
{1,1,1,1,1,1}};

//****************主函数************************
int main(void)
{
if(findpath(1,1)==1)
print_path();

return 0;
}
//*****************子函数***********************
int findpath(int row,int col)
{
int i=0,next_row,next_col;

while(i<4){

next_col=col+move[i].x;
next_row=row+move[i].y;

if(pic[next_row][next_col]==0){

pic[next_row][next_col]=2;

if(next_row

//给你修改了一下,可以了,主要修改了一下findpath的逻辑:
#include<stdio.h>
#define ROW 6
#define COL 6
//*************变量及函数声明*******************
typedef struct
{
int row;
int col;
}TRACK;

TRACK trk[36];
int trkind = 0;

typedef struct
{
int x;
int y;
}direction;

direction move[4]={
{1,0},
{-1,0},
{0,1},
{0,-1}};

int findpath(int row,int col);
void print_path();

//4×4迷宫图:
int pic[ROW][COL]={
{1,1,1,1,1,1},
{1,0,0,1,1,1},
{1,1,0,0,0,1},
{1,0,0,1,1,1},
{1,1,0,0,0,1},
{1,1,1,1,1,1}};

//****************主函数************************
int main(void)
{
if(findpath(1,1)==1)
print_path();

return 0;
}
//*****************子函数***********************
int findpath(int row,int col)
{
int i=0,j=0,next_row,next_col;

trk[trkind].row = row;