基地123 2022-11-26 21:27 采纳率: 90.2%
浏览 15
已结题

Devc++编译c语言,凡是有&的地方基本报错什么意思

问题遇到的现象和发生背景
用代码块功能插入代码,请勿粘贴截图
我想要达到的结果

用Devc++编译c语言,凡是有取地址符的地方基本·都报错是什么原因


```c

#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

typedef int DirectiveType;//定义方向类型
typedef int Status;
typedef struct{
    int row;
    int col;
}PosType;//通道块类型,代表的坐标(行,列)
 
typedef struct{
    int step;//在路径中的序号
    PosType seat;//位置坐标
    DirectiveType di;//方向 1代表东 2代表南 3代表西 4 代表北    
}SElemType;//栈元素类型,
 
typedef struct{
    SElemType *base;//栈底
    SElemType *top;//栈顶
    int stacksize;//栈的尺寸大小
}SqStack;//栈的类型,

#define STACK_INIT_SIZE 100//初始栈的大小
#define STACKINCREMENT  10//每次栈补充的大小
 
Status InitStack(SqStack &S)//栈的初始化
{
    S.base=(SElemType*)malloc(sizeof(SElemType)*STACK_INIT_SIZE);
    if(!S.base) exit(OVERFLOW);
    S.top=S.base;
    S.stacksize=STACK_INIT_SIZE;
    return OK;
}
Status GetTop(SqStack S,SElemType &e)//获取栈顶元素
{
    if(S.base == S.top) return ERROR;
    e=*(S.top-1);
    return OK;
}
Status Push(SqStack &S,SElemType e)//入栈
{
    if(S.top-S.base >= S.stacksize)
    {
        S.base=(SElemType *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(SElemType));
        if(!S.base) exit(OVERFLOW);
        S.top=S.base+S.stacksize;
        S.stacksize+=STACKINCREMENT;
    }
    *S.top++ = e;
    return OK;
}
Status Pop(SqStack &S,SElemType &e)//出栈
{
    if(S.top == S.base) return ERROR;
    e = * --S.top;
    return OK;
}
Status StackEmpty(SqStack S)//判断栈空
{
    return S.base == S.top;
}

#define ROW 10
#define COL 10
#define RANGE 100
 
typedef struct {
    int m,n;
    int arr[RANGE][RANGE];
}MazeType;//定义迷宫类型
 
Status CreatMaze(MazeType &Maze,int a,int b)//随机产生迷宫
{
    int i,j;
    srand((unsigned int)time(NULL));
    // 将迷宫的最外面包裹一堵墙,然后里面的随机产生墙或通路
    for(i = 0; i < a; i++)
    {        
        for(j = 0; j < b; j++)
        {
            // 迷宫的最外层是一堵墙
            if(i==0 || j==0 || i==a-1 || j==b-1)
            {
                maze.arr[i][j] = 1;
                printf("%2d", maze.arr[i][j]);
            }   
            else
            {
                if ((i == 1 && j == 1) || (i == (a - 2) && j == (b - 2)))
                {
                    maze.arr[i][j] = 0;         // 设置入口或出口
                }
                else 
                {
                    int ret = rand() % 2; // 生成 0 或 1的随机数
                    maze.arr[i][j] = ret;
                }
            }
                printf("%2d", maze.arr[i][j]);    
       }
            if(j == b - 1)
                printf("\n");
   }
}


Status Pass(MazeType Maze,PosType CurPos)//判断路径是否可通,看迷宫矩阵里存的是0还是1,0代表可通
{
    if(Maze.arr[CurPos.row][CurPos.col] == 0)
        return 1;
    else return 0;
}
Status FootPrint(MazeType &Maze,PosType CurPos)//如果能通过则留下足迹,防止下一次路径试探又回来
{
    Maze.arr[CurPos.row][CurPos.col]=2;
    return OK;
}
Status MarkPrint(MazeType &Maze,PosType CurPos)//走过的路径,但不能通过
{
    Maze.arr[CurPos.row][CurPos.col]=3;
    return OK;
}
SElemType CreatSElem(int step,PosType pos,int di)
{
    SElemType e;
    e.step = step;
    e.di = di;
    e.seat =pos;
    return e;
}
PosType NextPos(PosType CurPos,DirectiveType di)
{
    PosType Pos=CurPos;
    switch(di)
    {
    case 1:Pos.col++;break;//East
    case 2:Pos.row++;break;//south
    case 3:Pos.col--;break;//west
    case 4:Pos.row--;break;//north
    }
    return Pos;
}
Status PosEquare(PosType Pos1,PosType Pos2)//若当前路径为出口位置返回1,否则返回0
{
    if(Pos1.col == Pos2.col && Pos1.row == Pos2.row)
        return 1;
    else return 0;
}
void PrintMaze(MazeType Maze)
{
    int i,j;
    printf("  ");
    for(i=0;i<=COL+1;i++)
        printf("%2d",i);
    printf("\n");
    for(i=0;i<=ROW+1;i++)
    {
        printf("%2d",i);
        for(j=0;j<=COL+1;j++)
        {
            switch(Maze.arr[i][j])
            {
            case 0:printf("  ");break;//没有走过
            case 2:printf(" *");break;//走过且走的通
            case 3:printf(" @");break;//走过但不通
            case 1:printf(" #");break;//障碍
            }
        }
        printf("\n");
    }
}
Status MazePath(MazeType &Maze,PosType start,PosType end)
{
    SqStack S;
    SElemType e;
    InitStack(S);
    PosType CurPos= start;
    int Curstep=1;
    do
    {
        if(Pass(Maze,CurPos))
        {
            FootPrint(Maze,CurPos);
            e=CreatSElem(Curstep,CurPos,1);
            Push(S,e);
            if(PosEquare(CurPos,end)) return TRUE;
            CurPos=NextPos(CurPos,1);
            Curstep++;
        }
        else
        {
            if(!(StackEmpty(S)))
            {
                Pop(S,e);
                while(e.di == 4 && !StackEmpty(S))
                {
                    MarkPrint(Maze,e.seat);
                    Pop(S,e);
                }
                if(e.di<4)
                {
                    e.di++;Push(S,e);
                    CurPos=NextPos(e.seat,e.di);
                }
            }
        }
    }while(!StackEmpty(S));
    return FALSE;}
    
int main()
{
      char cmd;int i,j;
    PosType start,end;
    MazeType Maze;
    printf("请输入要生成的迷宫规格");
    scanf("%d %d",&a,&b);
    CreatMaze(Maze,a,b);
    printf("\n迷宫入口坐标:");
    scanf("%d%d",&start.row,&start.col);
    printf("\n迷宫出口坐标:");
    scanf("%d%d",&end.row,&end.col);
    
    if(MazePath(Maze,start,end))
    {
        PrintMaze(Maze);
    }
    else
    {
        printf("\nNO WAY");
    }
 
    system("pause");
 
    return 0;
}

```

  • 写回答

2条回答 默认 最新

  • 浪客 2022-11-27 09:44
    关注

    函数参数中的&是引用,c++中的概念,c里没有的。c里需要用 **
    比如Status InitStack(SqStack &S) 改为 Status InitStack(SqStack **S)
    SqStack *s
    InitStack(&s)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 5月23日
  • 已采纳回答 5月15日
  • 创建了问题 11月26日

悬赏问题

  • ¥15 Opencv配置出错
  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?