C语言迷宫问题报错,在51行的位置

#include<stdio.h>
#include<stdlib.h>
typedef int DataType;
struct SeqStack{
int maxnum;
int t;
DataType *s;
};
typedef struct SeqStack PSeqStack;
PSeqStack createEmptyStack_seq(int m)
{
PSeqStack pastack = (PSeqStack)malloc(sizeof(struct SeqStack));
if(pastack!=NULL){
pastack->s=(DataType
)malloc(sizeof(DataType)*m);
if(pastack->s){
pastack->maxnum=m;
pastack->t=-1;
return pastack;
}
else free (pastack);}}
int isEmptyStack_seq(PSeqStack pastack){
return(pastack->t==-1);}

DataType top_seq(PSeqStack pastack){
if(pastack->t==-1)
printf("It is empty!\n");
else
return(pastack->s[pastack->t]);}

void push_seq(PSeqStack pastack,DataType x){
if(pastack->t>=pastack->maxnum-1)
printf("Overflow!\n");
else{ pastack->t++;
pastack->s[pastack->t]=x; }}
void pop_seq(PSeqStack pastack){
if(pastack->t==-1)
printf("Underflow!\n");
else
pastack->t=pastack->t-1; }

void mazePath(int *maze[],int direction[],int x1,int y1,int x2,int y2,int M,int N)
//迷宫maze[m][n]中求从入口maze[x1][y1]到出口maze[x2][y2]的一条路径
//其中1<=x1,x2<=m-2,1<=y1,y2<=n-2
{
int i,j,k;
int g,h;
PSeqStack st;
DataType element;
st=createEmptyStack_seq(M
N);
maze[x1][y1]=2;
element.x=x1;
element.y=y1;
element.d=-1;
push_seq(st,element);
while(!isEmptyStack_seq(st))
{ element=top_seq(st);
pop_seq(st);
i=element.x;
j=element.y;
k=element.d+1;
while(k<=3){
g=i+direction[k][0];
h=j+direction[k][1];
if(g==x2&&h==y2&&maze[g][h]==0)
{ element.x=i;
element.y=j;
push_seq(st,element);
element.x=g;
element.y=h;
push_seq(st,element);
printf("the revers path is:\n");
while(!isEmptyStack_seq(st)){
element=top_seq(st);
pop_seq(st);
printf("the node is:%d %d\n",element.x,element.y);
}
return;
}
if(maze[g][h]==0){
maze[g][h]=2;
element.x=i;
element.y=j;
element.d=k;
push_seq(st,element);
i=g;
j=h;
k=-1; }
k=k+1; } }
printf("The path has not been found.\n");}

int main()
{
mazePath;
int a,b,c,d,e,f,i,k;
int *p1[8],*p2[4];
int direction[4][2]={0,1,1,0,0,-1,-1,0};
int maze[8][11]={1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,1,1,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1,0,1,1,1,0,0,0,1,1,1,1,0,0,0,1,0,1,1,0,1,1,1,1,0,0,1,0,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1};
for (i=0;i<8;i++)
p1[i]=maze[i];
for (k=0;k<4;k++)
p2[k]=direction[k];
printf("please input the location of enterance:\n");
scanf("%d%d",&a,&b);
printf("please input the location of exit\n");
scanf("%d%d",&c,&d);
printf("please input the maxnum of the location\n");
scanf("%d%d",&e,&f);
mazePath(p1,p2,a,b,c,d,e,f);
}
while(!isEmptyStack_seq(st))
{
element=top_seq(st);
pop_seq(st);
push_seq(be,element);
}
while(!isEmptyStack_seq(be))
{
element=top_seq(be);
pop_seq(be);
printf("the node is:%d %d\n",element.x,element.y);
}
return;


#include<stdio.h>
#include<stdlib.h>
typedef int DataType;
struct SeqStack{
int maxnum;
int t;
DataType *s;
};
typedef struct SeqStack *PSeqStack;
PSeqStack createEmptyStack_seq(int m)
{
PSeqStack pastack = (PSeqStack)malloc(sizeof(struct SeqStack));
if(pastack!=NULL){
pastack->s=(DataType*)malloc(sizeof(DataType)*m);
if(pastack->s){
   pastack->maxnum=m;
   pastack->t=-1;
   return pastack;
   }
   else free (pastack);}}
 int isEmptyStack_seq(PSeqStack pastack){
return(pastack->t==-1);}

DataType top_seq(PSeqStack pastack){
if(pastack->t==-1)
    printf("It is empty!\n");
    else
        return(pastack->s[pastack->t]);}

 void push_seq(PSeqStack pastack,DataType x){
if(pastack->t>=pastack->maxnum-1)
    printf("Overflow!\n");
    else{ pastack->t++;
        pastack->s[pastack->t]=x; }}
void pop_seq(PSeqStack pastack){
if(pastack->t==-1)
    printf("Underflow!\n");
    else
        pastack->t=pastack->t-1; }

void mazePath(int *maze[],int *direction[],int x1,int y1,int x2,int y2,int M,int N)
//迷宫maze[m][n]中求从入口maze[x1][y1]到出口maze[x2][y2]的一条路径
//其中1<=x1,x2<=m-2,1<=y1,y2<=n-2
{
int i,j,k;
int g,h;
PSeqStack st;
DataType element;
st=createEmptyStack_seq(M*N);
maze[x1][y1]=2;
element.x=x1;
element.y=y1;
element.d=-1;
push_seq(st,element);
while(!isEmptyStack_seq(st))
    { element=top_seq(st);
 pop_seq(st);
 i=element.x;
 j=element.y;
 k=element.d+1;
while(k<=3){
    g=i+direction[k][0];
    h=j+direction[k][1];
if(g==x2&&h==y2&&maze[g][h]==0)
{   element.x=i;
    element.y=j;
    push_seq(st,element);
    element.x=g;
    element.y=h;
    push_seq(st,element);
        printf("the revers path is:\n");
        while(!isEmptyStack_seq(st)){
            element=top_seq(st);
            pop_seq(st);
            printf("the node is:%d %d\n",element.x,element.y);
        }
  return;
    }
if(maze[g][h]==0){
    maze[g][h]=2;
    element.x=i;
    element.y=j;
    element.d=k;
 push_seq(st,element);
 i=g;
 j=h;
 k=-1; }
k=k+1; } }
printf("The path has not been found.\n");}

int main()
{
mazePath;
int a,b,c,d,e,f,i,k;
int *p1[8],*p2[4];
int direction[4][2]={0,1,1,0,0,-1,-1,0};
int maze[8][11]={1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,1,1,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1,0,1,1,1,0,0,0,1,1,1,1,0,0,0,1,0,1,1,0,1,1,1,1,0,0,1,0,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1};
for (i=0;i<8;i++)
   p1[i]=maze[i];
for (k=0;k<4;k++)
   p2[k]=direction[k];
printf("please input the location of enterance:\n");
scanf("%d%d",&a,&b);
printf("please input the location of exit\n");
scanf("%d%d",&c,&d);
printf("please input the maxnum of the location\n");
scanf("%d%d",&e,&f);
mazePath(p1,p2,a,b,c,d,e,f);
}
while(!isEmptyStack_seq(st))
{
    element=top_seq(st);
    pop_seq(st);
    push_seq(be,element);
}
while(!isEmptyStack_seq(be))
{
    element=top_seq(be);
    pop_seq(be);
    printf("the node is:%d %d\n",element.x,element.y);
}
return;

DataType应该要是个结构体才对。你一开始定义了typedef int DataType; 然后DataType element; 接着element.x=x1;element.y=y1; element.d=-1;
int类型显然是不能访问成员的。


#include<stdio.h>
#include<stdlib.h>
typedef int DataType;
struct SeqStack{
int maxnum;
int t;
DataType *s;
};
typedef struct SeqStack *PSeqStack;
PSeqStack createEmptyStack_seq(int m)
{
PSeqStack pastack = (PSeqStack)malloc(sizeof(struct SeqStack));
if(pastack!=NULL){
pastack->s=(DataType*)malloc(sizeof(DataType)*m);
if(pastack->s){
   pastack->maxnum=m;
   pastack->t=-1;
   return pastack;
   }
   else free (pastack);}}
 int isEmptyStack_seq(PSeqStack pastack){
return(pastack->t==-1);}

DataType top_seq(PSeqStack pastack){
if(pastack->t==-1)
    printf("It is empty!\n");
    else
        return(pastack->s[pastack->t]);}

 void push_seq(PSeqStack pastack,DataType x){
if(pastack->t>=pastack->maxnum-1)
    printf("Overflow!\n");
    else{ pastack->t++;
        pastack->s[pastack->t]=x; }}
void pop_seq(PSeqStack pastack){
if(pastack->t==-1)
    printf("Underflow!\n");
    else
        pastack->t=pastack->t-1; }

void mazePath(int *maze[],int *direction[],int x1,int y1,int x2,int y2,int M,int N)
//迷宫maze[m][n]中求从入口maze[x1][y1]到出口maze[x2][y2]的一条路径
//其中1<=x1,x2<=m-2,1<=y1,y2<=n-2
{
int i,j,k;
int g,h;
PSeqStack st;
DataType element;
st=createEmptyStack_seq(M*N);
maze[x1][y1]=2;
element.x=x1;
element.y=y1;
element.d=-1;
push_seq(st,element);
while(!isEmptyStack_seq(st))
    { element=top_seq(st);
 pop_seq(st);
 i=element.x;
 j=element.y;
 k=element.d+1;
while(k<=3){
    g=i+direction[k][0];
    h=j+direction[k][1];
if(g==x2&&h==y2&&maze[g][h]==0)
{   element.x=i;
    element.y=j;
    push_seq(st,element);
    element.x=g;
    element.y=h;
    push_seq(st,element);
        printf("the revers path is:\n");
        while(!isEmptyStack_seq(st)){
            element=top_seq(st);
            pop_seq(st);
            printf("the node is:%d %d\n",element.x,element.y);
        }
  return;
    }
if(maze[g][h]==0){
    maze[g][h]=2;
    element.x=i;
    element.y=j;
    element.d=k;
 push_seq(st,element);
 i=g;
 j=h;
 k=-1; }
k=k+1; } }
printf("The path has not been found.\n");}

int main()
{
mazePath;
int a,b,c,d,e,f,i,k;
int *p1[8],*p2[4];
int direction[4][2]={0,1,1,0,0,-1,-1,0};
int maze[8][11]={1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,1,1,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1,0,1,1,1,0,0,0,1,1,1,1,0,0,0,1,0,1,1,0,1,1,1,1,0,0,1,0,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1};
for (i=0;i<8;i++)
   p1[i]=maze[i];
for (k=0;k<4;k++)
   p2[k]=direction[k];
printf("please input the location of enterance:\n");
scanf("%d%d",&a,&b);
printf("please input the location of exit\n");
scanf("%d%d",&c,&d);
printf("please input the maxnum of the location\n");
scanf("%d%d",&e,&f);
mazePath(p1,p2,a,b,c,d,e,f);
}
while(!isEmptyStack_seq(st))
{
    element=top_seq(st);
    pop_seq(st);
    push_seq(be,element);
}
while(!isEmptyStack_seq(be))
{
    element=top_seq(be);
    pop_seq(be);
    printf("the node is:%d %d\n",element.x,element.y);
}
return;

用代码块发一下,不然会缺少符号

给个初始化值