迷宫问题C语言编译执行出错

来源:百度知道 编辑:UC知道 时间:2024/05/30 19:06:08
用的C/C++程序设计学习与实验系统2010写的,应该是VC的编译器
编译时有意个warning C4715: 'move': not all control paths return a value
执行时出现"TempFile.exe-应用程序错误"
源程序如下:
#include "stdio.h"
struct PathStack
{
int row;
int col;
int dire;
} *path;

int move(int maze[][11],int n,int m)
{
int i,j,g,h,top,dire;
int change[4][2]=
{
{0,1},
{1,0},
{0,-1},
{-1,0}
};
top=1;
i=1;j=1;dire=0;
path[top].row=i;
path[top].col=j;
path[top].dire=dire;
maze[i][j]=-1;
while(top>0||dire<4)
{
if(dire<4)
{
g=i+change[dire][0];
h=j+change[dire][1];
if(maze[g][h]!=1&&maze[g][h]!=-1)
{
maze[g][h]=-1;
top++;
path[top].row=g;
path[top].col=h;
path[top].dire=dire;
i=g;j=h;dire=0;
if(i==n-2&&j==m-2) return top;
}
else dire++;<

path只是个指针 你还没给他分配空间 在move函数里就对他进行赋值了

如果你这个path是个堆栈的话 你至少也得编一个出栈 一个进栈函数

看你代码,path是一个结构数组,那么path的定义就不对了。应该用
struct PathStack path[10];
10是我随便写的,应根据实际情况修改。