想玩迷宫。。。编译错误,我快疯了在,怎么搞!

BetterChinglish 2019-09-20 12:56:49
不知道问题出在哪,显示编译错误(ld returned 1exit status) #include <stdio.h> #include <stdlib.h> #include <windows.h> #include <conio.h> int getch(void) { char a[50][50]={"######", "#O # ", "# ## #", "# # #", "## #", "######", }; int i,p,q,x,y; char ch; x=1;y=1;p=1;q=5; for(i=0;i<=5;i++) puts(a[i]); while(x!=p||y!=q) { ch=getch(); if(ch=='s') { if(a[x+1][y]!='#') { a[x][y]=' '; x++; a[x][y]='O'; } } if(ch=='w') { if(a[x-1][y]!='#') { a[x][y]=' '; x--; a[x][y]='O'; } } if(ch=='a') { if(a[x][y-1]!='#') { a[x][y]=' '; y--; a[x][y]='O'; } } if(ch=='d') { if(a[x][y+1]!='#') { a[x][y]=' '; y++; a[x][y]='O'; } } system("cls"); for(i=0;i<=5;i++) { puts(a[i]); } } system("cls"); printf("you win!\n"); Sleep(1000); return 0; }
...全文
59 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2019-09-21
  • 打赏
  • 举报
回复
你的主函数呢
BetterChinglish 2019-09-21
  • 打赏
  • 举报
回复
引用 2 楼 wowpH的回复:
main函数都没看到
一开始是写的int main(),后面说要调用 int getch(),然后我懵了
赵4老师 2019-09-20
  • 打赏
  • 举报
回复
仅供参考:
/**
 * @Title  老鼠走迷宫的拓展探究
 * @Author 孙琨
 * @Date   2013-11-16
 * @At     XUST
 * @All Copyright by 孙琨
 *
 */

#include <iostream>
using namespace std;

int maze[9][9] = { // 初始化迷宫,英文maze为“迷宫”
    {2,2,2,2,2,2,2,2,2},
    {2,0,0,0,0,0,0,0,2},
    {2,0,2,2,0,2,2,0,2},
    {2,0,2,0,0,2,0,0,2},
    {2,0,2,0,2,0,2,0,2},
    {2,0,0,0,0,0,2,0,2},
    {2,2,0,2,2,0,2,2,2},
    {2,0,0,0,0,0,0,0,2},
    {2,2,2,2,2,2,2,2,2}
};

int startI = 1,startJ = 1; // 入口行列坐标
int endI = 7,endJ = 7;     // 出口行列坐标

void visit(int i,int j)  // 自动搜寻路径
{
    int m,n;

    maze[i][j] = 1;

    if((i == endI) && (j == endJ))
    {
        cout << endl << "显示路径:" << endl;
        for(m=0; m<9; m++)
        {
            for(n=0; n<9; n++)
            {
                if(maze[m][n] == 2)
                    cout << "■";
                else if(maze[m][n] == 1)
                    cout << "♀";
                else
                    cout << "  ";
            }
            cout << endl;
        }
    }

    if(maze[i][j+1] == 0)
        visit(i,j+1);
    if(maze[i+1][j] == 0)
        visit(i+1,j);
    if(maze[i][j-1] == 0)
        visit(i,j-1);
    if(maze[i-1][j] == 0)
        visit(i-1,j);

    maze[i][j] = 0;

}

int main(void)
{
    int i,j;

    cout << "显示迷宫: " << endl;
    for(i=0; i<9; i++)
    {
        for(j=0; j<9; j++)
        {
            if(maze[i][j] == 2)
                cout << "■" ;
            else
                cout << "  " ;
        }
        cout << endl;
    }

    visit(startI,startJ);

    return 0;
}

wowpH 2019-09-20
  • 打赏
  • 举报
回复
main函数都没看到
BetterChinglish 2019-09-20
  • 打赏
  • 举报
回复
身为小白的我太难了,电子版啊哈c上抄过来的,然后运行不了🙃🙃🙃

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧