#include"stdio.h"
#include"malloc.h"
#include"stdlib.h"typedef struct
{
int x, y;  //坐标
int dir;  //方向
}ElemType;typedef struct StackNode//构造栈
{
ElemType *base;
ElemType *top;
int stacksize;
}SqStack;
typedef struct 
{
int maze[100][100];
}MG;
int InitStack(SqStack *head)//初始化栈
{
head->base=(ElemType *)malloc(100*sizeof(ElemType));
if(!head->base)
{
printf("memory allocation failed,goodbye");
exit(1);
}
head->top=head->base;
head->stacksize=100;
return 1;
}int Push(SqStack *head,ElemType e)//进栈操作
{
if(head->top-head->base>=head->stacksize)
{
head->base = (ElemType *)realloc(head->base,(head->stacksize+10)*sizeof(ElemType));
if (!head->base)
{
printf("memory allocation failed,goodbye");
exit(1);
}
head->top =head->base+head->stacksize;
head->stacksize +=10;
}
*head->top++=e;
return 1;
}int Pop(SqStack *head,ElemType *e)//出栈操作
{
if(head->top==head->base)
{
return 0;
}
*e=*--head->top;
//printf("%d\n",e);

int GetPOp(SqStack *head,ElemType *e);
{
if(head->top==head->base)
return 0;
e=(head->top-1);
return 1;
}

/*int StackEmpty(SqStack *head)//判断栈是否为空
{
if(head->top==head->base)
return 1;
else
return 0;
}*/MG printmazeA(MG ma)
{
int maze[10][10]=
{{0,0,0,0,0,0,0,0,0,0},
{0,2,1,0,1,1,1,0,1,0},
{0,1,1,0,1,1,1,0,1,0},
{0,1,1,1,1,0,0,1,1,0},
{0,1,0,0,0,1,1,1,1,0},
{0,1,1,1,0,1,1,1,1,0},
{0,1,0,1,1,1,0,1,1,0},
    {0,1,0,0,0,1,0,0,1,0},
{0,0,1,1,1,1,1,1,2,0},
{0,0,0,0,0,0,0,0,0,0}
};

for(int i=0;i<10;i++)
{
printf("\n");
for(int j=0;j<10;j++)
{
if(maze[i][j]==1)
printf("□");
if(maze[i][j]==0)
printf("■");
if(maze[i][j]==0)
printf("☆");

}
}
for(int i=0;i<10;i++ )
{
for(int j=0;j<10;j++)
{
ma.maze[i][j]=maze[i][j];
}
}

return ma;
}






void findway(SqStack *head,MG ma)
{
int startx=1,starty=1,endx=8,endy=8;
road *a;
road *e;
e.x=startx;
e.y=starty;
e.dir=0;
do
{
switch(e.dir)
{
case 0:{
e.y++;
a=GetTop(head ,e);
if(a.x==e.x&&a.y==e.y)
{
e.dir++;
}
if(ma.maze[e.x][e.y]==0)
{
e.dir++;
break;
}
else
{
Push(head,e);
e.dir=0;
break;
}
   }
case 1:{
e.x++;
a=GetTop(head ,e);
if(a.x==e.x&&a.y==e.y)
{
e.dir++;
}
if(ma.maze[e.x][e.y]==0)
{
e.dir++;
break;
}
else
{
Push(head,e);
e.dir=0;
break;
}
   }
case 2:{
e.y--;
a=GetTop(head ,e);
if(a.x==e.x&&a.y==e.y)
{
e.dir++;
}
if(ma.maze[e.x][e.y]==0)
{
e.dir++;
break;
}
else
{
Push(head,e);
e.dir=0;
break;
}
   }
case 3:{
e.x--;
a=GetTop(head ,e);
if(a.x==e.x&&a.y==e.y)
{
e.dir++;
}
if(ma.maze[e.x][e.y]==0)
{
e.dir++;
break;
}
else
{
Push(head,e);
e.dir=0;
break;
}
   }
case 4: {

if(head.top!=head.base)
{
Pop(head,e);
e=GetTop(head,e);
e.dir++;
break:
}
else
{
printf("\n这个迷宫没有出路!\n");
}

}
if(e.x==endx&&e.y==endy)
{
break;
}
}while(head.top!=head.base); if(head.top!=head.base)
{
do
{
e=GetTop(head,e);
ma.maze[e.x][e.y]=2;
Pop(head,e);
}
while(head.top!=head.base);
}
}
}void printma(MG ma)
{
for(int i=0;i<10;i++)
{
printf("\n");
for(int j=0;j<10;j++)
{
if(ma.maze[i][j]==1)
printf("□");
if(ma.maze[i][j]==0)
printf("■");
if(ma.maze[i][j]==0)
printf("☆");

}
}
}void main()
{
SqStack *head; MG ma;
InitStack(head);
ma=printmazeA(ma);
findway(head,ma);
printma(ma);
}
mig.cpp
D:\专利\mig.cpp(83) : error C2601: 'printmazeA' : local function definitions are illegal
D:\专利\mig.cpp(128) : error C2601: 'findway' : local function definitions are illegal
D:\专利\mig.cpp(250) : error C2601: 'printma' : local function definitions are illegal
D:\专利\mig.cpp(268) : error C2601: 'main' : local function definitions are illegal
D:\专利\mig.cpp(277) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.mig.obj - 1 error(s), 0 warning(s)

解决方案 »

  1.   

    local function?函数层次对吗?
      

  2.   

    我觉得你是不是应该从D:\专利\mig.cpp(277) : fatal error C1004: unexpected end of file found这个错误开始排查?获取这个问题改了,之前的问题就解决了。
      

  3.   

    fatal error C1004: unexpected end of file found这个问题应该如何该呢?
      

  4.   

    D:\专利\mig.cpp(83) : error C2601: 'printmazeA' : local function definitions are illegal
    该函数的一个 却结束 ‘}’
      

  5.   

    错误实在太多!#include"stdio.h"
    #include"malloc.h"
    #include"stdlib.h"typedef struct
    {
    int x, y; //坐标
    int dir; //方向
    }ElemType;typedef struct StackNode//构造栈
    {
    ElemType *base;
    ElemType *top;
    int stacksize;
    }SqStack;
    typedef struct  
    {
    int maze[100][100];
    }MG;int InitStack(SqStack *head)//初始化栈
    {
    head->base=(ElemType *)malloc(100*sizeof(ElemType));
    if(!head->base)
    {
    printf("memory allocation failed,goodbye");
    exit(1);
    }
    head->top=head->base;
    head->stacksize=100;
    return 1;
    }int Push(SqStack *head,ElemType e)//进栈操作
    {
    if(head->top-head->base>=head->stacksize)
    {
    head->base = (ElemType *)realloc(head->base,(head->stacksize+10)*sizeof(ElemType));
    if (!head->base)
    {
    printf("memory allocation failed,goodbye");
    exit(1);
    }
    head->top =head->base+head->stacksize;
    head->stacksize +=10;
    }
    *head->top++=e;
    return 1;
    }int Pop(SqStack *head,ElemType *e)//出栈操作
    {
    if(head->top==head->base)
    {
    return 0;
    }
    *e=*--head->top;
    return 0;
    //printf("%d\n",e);
    }int GetPop(SqStack *head,ElemType *e)
    {
    if(head->top==head->base) return 0;
    e=(head->top-1);
    return 1;
    }/*int StackEmpty(SqStack *head)//判断栈是否为空
    {
    if(head->top==head->base)
    return 1;
    else
    return 0;
    }*/MG printmazeA(MG ma)
    {
    int i,j;
    int maze[10][10]=
    {{0,0,0,0,0,0,0,0,0,0},
    {0,2,1,0,1,1,1,0,1,0},
    {0,1,1,0,1,1,1,0,1,0},
    {0,1,1,1,1,0,0,1,1,0},
    {0,1,0,0,0,1,1,1,1,0},
    {0,1,1,1,0,1,1,1,1,0},
    {0,1,0,1,1,1,0,1,1,0},
    {0,1,0,0,0,1,0,0,1,0},
    {0,0,1,1,1,1,1,1,2,0},
    {0,0,0,0,0,0,0,0,0,0}
    };

    for(i=0;i<10;i++)
    {
    printf("\n");
    for(j=0;j<10;j++)
    {
    if(maze[i][j]==1) printf("□");
    if(maze[i][j]==0) printf("■");
    if(maze[i][j]==0) printf("☆");
    }
    }
    for(i=0;i<10;i++ )
    {
    for(j=0;j<10;j++)
    {
    ma.maze[i][j]=maze[i][j];
    }
    }

    return ma;
    }
    void findway(SqStack *head,MG ma)
    {
    int startx=1,starty=1,endx=8,endy=8;
    ElemType a;
    ElemType e;
    e.x=startx;
    e.y=starty;
    e.dir=0;
    //
    a.x=startx;
    a.y=starty;
    a.dir=0; switch(e.dir)
    {
    case 0:
    e.y++;
    GetPop(head , &e);
    if(a.x==e.x && a.y==e.y)
    {
    e.dir++;
    }
    if(ma.maze[e.x][e.y]==0)
    {
    e.dir++;
    break;
    }
    else
    {
    Push(head,e);
    e.dir=0;
    break;
    }
    break;// 9
    case 1:
    e.x++;
    GetPop(head,&e);
    if(a.x==e.x && a.y==e.y)
    {
    e.dir++;
    }
    if(ma.maze[e.x][e.y]==0)
    {
    e.dir++;
    break;
    }
    else
    {
    Push(head,e);
    e.dir=0;
    break;
    }
    break;//1
    case 2:
    e.y--;
    GetPop(head ,&e);
    if((a.x ==e.x) && (a.y==e.y))
    {
    e.dir++;
    }
    if(ma.maze[e.x][e.y]==0)
    {
    e.dir++;
    break;
    }
    else
    {
    Push(head,e);
    e.dir=0;
    break;
    }
    break;//2
    case 3:
    e.x--;
    GetPop(head , &e);
    if(a.x==e.x && a.y==e.y)
    {
    e.dir++;
    }
    if(ma.maze[e.x][e.y]==0)
    {
    e.dir++;
    break;
    }
    else
    {
    Push(head,e);
    e.dir=0;
    break;
    }
    break;//3
    case 4:
    if(head->top!=head->base)
    {
    Pop(head,&e);
    GetPop(head,&e);
    e.dir ++;
    break;
    }
    else
    {
    printf("\n这个迷宫没有出路!\n");
    }

    do
    {
    if(e.x==endx&&e.y==endy)
    {
    break;
    }
    }while(head->top!=head->base); if(head->top!=head->base)
    {
    do
    {
    GetPop(head,&e);
    ma.maze[e.x][e.y]=2;
    Pop(head,&e);
    } while(head->top!=head->base);
    }
    break;// end 4
    }//switch(e.dir)
    }//////////////////////////
    void printma(MG ma)
    {
    int i,j;
    for( i=0;i<10;i++)
    {
    printf("\n");
    for(j=0;j<10;j++)
    {
    if(ma.maze[i][j]==1) printf("□");
    if(ma.maze[i][j]==0) printf("■");
    if(ma.maze[i][j]==0) printf("☆");
    }
    }
    }void main()
    {
    SqStack *head=0;

    MG ma;
    InitStack(head);
    ma=printmazeA(ma);
    findway(head,ma);
    printma(ma);
    }
      

  6.   

    这样修改,编译能通过,但无法运行,比如:
     SqStack *head=0;
    //...
     findway(head,ma);head都没分配内存就用了,那肯定导致AV呀。还有这findway的算法也是错误,可能导致穿墙,或者循环。
      

  7.   

    MG printmazeA(MG ma)这个函数有问题