请教. 编译一直[Error] expected primary-expression before'*'token

acwodek 2015-05-03 12:41:41
#ifndef MAZE_CREATE_H
#define Maze_Create_H
#define ROWS 40
#define COLS 60
#define DIRECTION_NUM 4
#define DIRECTION_EAST 0
#define DIRECTION_SOUTH 1
#define DIRECTION_WEST 2
#define DIRECTION_NORTH 3
#include<iostream>
using namespace std;
typedef struct cell
{
bool door[DIRECTION_NUM];
}cell;
void create_Maze(int *cells, cell (*maze)[COLS]);
static void init_Maze(int *cells, cell (*maze)[COLS]);
static bool is_Connect(const int * const cells, int c1, int c2);
static bool all_Connect(const int * const cells);
static void union_Cells(int *cells, int c1, int c2);
#endif

/*
* 迷宫实现类:Maze_Create.cpp
*/
#include<stdlib.h>
#include <time.h>

int cells[ROWS*COLS];
cell maze[ROWS][COLS];
void create_Maze(int *cells, cell (*maze)[COLS])
{
int direction, c1, c2;
int CELL_NUM = ROWS*COLS;
init_Maze(cells, maze);
srand((unsigned)time(NULL));
while(1)
{
c1 = rand()%CELL_NUM;
direction = rand()%DIRECTION_NUM;
switch(direction)
{
case DIRECTION_EAST:
if(c1%COLS == COLS-1) c2 = -1;
else c2 = c1 + 1;
break;
case DIRECTION_SOUTH:
if((ROWS-1) == (c1 - c1%COLS)/COLS) c2 = -1;
else c2 = c1 + COLS;
break;
case DIRECTION_WEST:
if(c1%COLS == 0) c2 = -1;
else c2 = c1 - 1;
break;
case DIRECTION_NORTH:
if(0 == (c1 - c1%COLS)/COLS) c2 = -1;
else c2 = c1 - COLS;
break;
default:
printf("error on random numbers/n");
exit(0);
break;
}
if(c2 < 0) continue;
if(is_Connect(cells, c1, c2)) continue;
else
{
union_Cells(cells, c1, c2);
maze[(c1-c1%COLS)/COLS][c1%COLS].door[direction] = true;
maze[(c2-c2%COLS)/COLS][c2%COLS].door[(direction+2)%DIRECTION_NUM] = true;
}
if(is_Connect(cells, 0, CELL_NUM - 1)) break;
}
}
void init_Maze(int *cells, cell (*maze)[COLS])
{
int i, j, k;
for(i = 0; i < ROWS; i++)
{
for(j = 0; j < COLS; j++)
{
for(k = 0; k < DIRECTION_NUM; k++)
maze[i][j].door[k] = false;
}
}
maze[0][0].door[DIRECTION_WEST] = true;
maze[ROWS-1][COLS-1].door[DIRECTION_EAST] = true;

for(i = 0; i < ROWS*COLS; i++)
{
cells[i] = -1;
}
}
bool is_Connect(const int * const cells, int c1, int c2)
{
while(cells[c1] >= 0) c1 = cells[c1];
while(cells[c2] >= 0) c2 = cells[c2];
if(c1 == c2)
return true;
else
return false;
}
/*
* if the two adjacent rooms are not connect, remove the wall between them(or fix a door)
*/
void union_Cells(int *cells, int c1, int c2)
{
while(cells[c1] >= 0) c1 = cells[c1];
while(cells[c2] >= 0) c2 = cells[c2];
if(cells[c1] > cells[c2])
{
cells[c1] = c2;
}
else
{
if(cells[c1] == cells[c2]) cells[c1]--;
cells[c2] = c1;
}
}
bool all_Connect(const int * const cells)
{
int i, count_root = 0;
for(i = 0; i < ROWS*COLS; i++)
{
if(cells[i] < 0) count_root++;
}
if(1 == count_root)
return true;
else
return false;
}
int main()
{
int *cells;
create_Maze(cells,cell*maze[COLS]);
}
一个生成迷宫的程序,函数已经写好了,但是主程序引用一直出错,暂时看不出怎么改,各位帮帮忙。
...全文
1698 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 楼主 acwodek 的回复:
#ifndef MAZE_CREATE_H #define Maze_Create_H #define ROWS 40 #define COLS 60 #define DIRECTION_NUM 4 #define DIRECTION_EAST 0 #define DIRECTION_SOUTH 1 #define DIRECTION_WEST 2 #define DIRECTION_NORTH 3 #include<iostream> using namespace std; typedef struct cell { bool door[DIRECTION_NUM]; }cell; void create_Maze(int *cells, cell (*maze)[COLS]); static void init_Maze(int *cells, cell (*maze)[COLS]); static bool is_Connect(const int * const cells, int c1, int c2); static bool all_Connect(const int * const cells); static void union_Cells(int *cells, int c1, int c2); #endif /* * 迷宫实现类:Maze_Create.cpp */ #include<stdlib.h> #include <time.h> int cells[ROWS*COLS]; cell maze[ROWS][COLS]; void create_Maze(int *cells, cell (*maze)[COLS]) { int direction, c1, c2; int CELL_NUM = ROWS*COLS; init_Maze(cells, maze); srand((unsigned)time(NULL)); while(1) { c1 = rand()%CELL_NUM; direction = rand()%DIRECTION_NUM; switch(direction) { case DIRECTION_EAST: if(c1%COLS == COLS-1) c2 = -1; else c2 = c1 + 1; break; case DIRECTION_SOUTH: if((ROWS-1) == (c1 - c1%COLS)/COLS) c2 = -1; else c2 = c1 + COLS; break; case DIRECTION_WEST: if(c1%COLS == 0) c2 = -1; else c2 = c1 - 1; break; case DIRECTION_NORTH: if(0 == (c1 - c1%COLS)/COLS) c2 = -1; else c2 = c1 - COLS; break; default: printf("error on random numbers/n"); exit(0); break; } if(c2 < 0) continue; if(is_Connect(cells, c1, c2)) continue; else { union_Cells(cells, c1, c2); maze[(c1-c1%COLS)/COLS][c1%COLS].door[direction] = true; maze[(c2-c2%COLS)/COLS][c2%COLS].door[(direction+2)%DIRECTION_NUM] = true; } if(is_Connect(cells, 0, CELL_NUM - 1)) break; } } void init_Maze(int *cells, cell (*maze)[COLS]) { int i, j, k; for(i = 0; i < ROWS; i++) { for(j = 0; j < COLS; j++) { for(k = 0; k < DIRECTION_NUM; k++) maze[i][j].door[k] = false; } } maze[0][0].door[DIRECTION_WEST] = true; maze[ROWS-1][COLS-1].door[DIRECTION_EAST] = true; for(i = 0; i < ROWS*COLS; i++) { cells[i] = -1; } } bool is_Connect(const int * const cells, int c1, int c2) { while(cells[c1] >= 0) c1 = cells[c1]; while(cells[c2] >= 0) c2 = cells[c2]; if(c1 == c2) return true; else return false; } /* * if the two adjacent rooms are not connect, remove the wall between them(or fix a door) */ void union_Cells(int *cells, int c1, int c2) { while(cells[c1] >= 0) c1 = cells[c1]; while(cells[c2] >= 0) c2 = cells[c2]; if(cells[c1] > cells[c2]) { cells[c1] = c2; } else { if(cells[c1] == cells[c2]) cells[c1]--; cells[c2] = c1; } } bool all_Connect(const int * const cells) { int i, count_root = 0; for(i = 0; i < ROWS*COLS; i++) { if(cells[i] < 0) count_root++; } if(1 == count_root) return true; else return false; } int main() { int *cells; create_Maze(cells,cell*maze[COLS]); } 一个生成迷宫的程序,函数已经写好了,但是主程序引用一直出错,暂时看不出怎么改,各位帮帮忙。
create_Maze(cells,cell*maze[COLS]); cell是一个结构体?cell*maze????不觉得有问题吗?
赵4老师 2015-05-04
  • 打赏
  • 举报
回复
偶遇到类似问题都是用 “每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。” 的方法解决的。
Isnis-fallen 2015-05-03
  • 打赏
  • 举报
回复
int *cells 未初始化
2022 / 01/ 30: 新版esptool 刷micropython固件指令不是 esptool.py cmd... 而是 esptool cmd... 即可;另外rshell 在 >= python 3.10 的时候出错解决方法可以查看:  已于2022年发布的: 第二章:修复rshell在python3.10出错 免费内容: https://edu.csdn.net/course/detail/29666 micropython语法和python3一样,编写起来非常方便。如果你快速入门单片机玩物联网而且像轻松实现各种功能,那绝力推荐使用micropython。方便易懂易学。 同时如果你懂C语音,也可以用C写好函数并编译进micropython固件里然后进入micropython调用(非必须)。 能通过WIFI联网(2.1章),也能通过sim卡使用2G/3G/4G/5G联网(4.5章)。 为实现语音控制,本教程会教大家使用tensorflow利用神经网络训练自己的语音模型并应用。为实现通过网页控制,本教程会教大家linux(debian10 nginx->uwsgi->python3->postgresql)网站前后台入门。为记录单片机传输过来的数据, 本教程会教大家入门数据库。  本教程会通过通俗易懂的比喻来讲解各种原理与思路,并手把手编写程序来实现各项功能。 本教程micropython版本是 2019年6月发布的1.11; 更多内容请看视频列表。  学习这门课程之前你需要至少掌握: 1: python3基础(变量, 循环, 函数, 常用库, 常用方法)。 本视频使用到的零件与淘宝上大致价格:     1: 超声波传感器(3)     2: MAX9814麦克风放大模块(8)     3: DHT22(15)     4: LED(0.1)     5: 8路5V低电平触发继电器(12)     6: HX1838红外接收模块(2)     7:红外发射管(0.1),HX1838红外接收板(1)     other: 电表, 排线, 面包板(2)*2,ESP32(28)  

64,661

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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