C语言数据结构,迷宫问题,求救

代码有错误的,可是我一直找不为什么错误?
#include<stdio.h>
#include<malloc.h>
#include <stdlib.h>
#include <time.h>
#define MAXSIZE 256
#define m 6
#define n 8

typedef struct
{
int x;
int y;
int d;
}datatype;
typedef struct
{
datatype data[MAXSIZE];
int top;
}SeqStack;
typedef struct
{int x;
int y;}
item;

SeqStack *Init_SeqStack()
{
SeqStack *s;
s=(SeqStack *)malloc(sizeof(SeqStack));
s->top=-1;
return s;
}
int Empty_SeqStack(SeqStack *s)
{
if(s->top==-1)
return 1;
else
return 0;
}
int Push_SeqStack(SeqStack *s,datatype x)
{if(s->top==MAXSIZE-1)
return 0;
else{s->top++;
s->data[s->top]=x;
return 1;}
}

int Pop_SeqStack(SeqStack *s,datatype *x)
{if(Empty_SeqStack(s))
return 0;
else{
*x=s->data[s->top];
s->top--;}
return 1;}
void maze_init(int (*maze)[n+2])
{int i,j;
srand(time(0));
for(i=0;i<m+2;i++)
{for(i=0;j<n+2;j++)
{maze[i][j]=rand()%2;}}
for(j=0;j<m+2;j++)
{maze[0][j]=1;
maze[m+2][j]=1;}
for(i=0;i<n+2;i++)
{maze[i][0]=1;
maze[i][n+2]=1;}
return;
}

void move_init(item *move)
{
move[0].x=0 ; move[0].y=1;
move[1].x=1 ; move[1].y=1;
move[2].x=1 ; move[2].y=0;
move[3].x=1 ; move[3].y=-1;
move[4].x=0 ; move[4].y=-1;
move[5].x=-1 ; move[5].y=-1;
move[6].x=-1 ; move[6].y=0;
move[7].x=-1 ; move[7].y=1;
}

int path(int (*maze)[n+2],item *move,SeqStack *s)
{
datatype temp;
int x,y,d,i,j;

temp.x=1;temp.y=1;temp.d=-1;
Push_SeqStack(s,temp);
while(!Empty_SeqStack(s))
{
Pop_SeqStack(s,&temp);
x=temp.x;y=temp.y;d=temp.d+1;
while(d<8)
{
i=x+move[d].x;
j=y+move[d].y;
if(maze[i][j]=0)
{temp.x=x;temp.y=y;temp.d=d;
Push_SeqStack(s,temp);
x=i;y=j;maze[x][y]=-1;
if(x==m&&y==n)
return 1;
else
d=0;}
else d++;}}
return 0;
}
void main()
{
int n,m=1,g;
SeqStack *S;
while(m)
{
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("1.初始化\n");
printf("2.建立迷宫\n");
printf("0.退出\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入你需要进行的操作:");
scanf("%d",&n);
switch(n)
{
case 1:S=init_SeqStack();break;
case 2:{int maze[m+2][n+2];
datatype temp;
item move[8];
maze_init(maze);
move_init(move);
g=path(maze,move,S);
if(g==1)

printf("迷宫有路\n");
else
printf("迷宫无路\n");

while(!Empty_SeqStack(S))
{
Pop_SeqStack(S,&temp);
printf("(%d,%d)-->",temp.x,temp.y);}
break;}
case 0:m=0;}

}
}

不能运行的错误在主函数,改后能运行,好像还有错误不能创建迷宫
void main()
{
int n,m=1,g;//这句有问题,因为你前面有宏定义n,m,造成冲突可改成
int n1,m1=1,g;
SeqStack *S;
while(m1)
{
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("1.初始化\n");
printf("2.建立迷宫\n");
printf("0.退出\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入你需要进行的操作:");
scanf("%d",&n1);
switch(n1)
{
case 1:S=Init_SeqStack();break;//这地方的函数名称也写错了
case 2:{int maze[m+2][n+2];
datatype temp;
item move[8];
maze_init(maze);
move_init(move);
g=path(maze,move,S);
if(g==1)

printf("迷宫有路\n");
else
printf("迷宫无路\n");

while(!Empty_SeqStack(S))
{
Pop_SeqStack(S,&temp);
printf("(%d,%d)-->",temp.x,temp.y);}
break;}
case 0:m1=0;}//

}
}追问

后来我都发现,不能创建迷宫的原因是void maze_init(int (*maze)[n+2])
第二个for的j打成i啦

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-03-28
你可以把问题描述一下吗?这个程序没有注释,看起来有点困难
第2个回答  2012-03-28
能把错误提示给发上来么?warning