gpt4 book ai didi

c - 在 ';' void createCell(struct cell myCell, int type, int immutable) 之前,我一直期望 '('、标识符或 'void'

转载 作者:太空宇宙 更新时间:2023-11-04 07:53:34 26 4
gpt4 key购买 nike

所以,我一直让编译器告诉我在我的第一个函数声明之前有一个错误。在此之前,我定义了一个枚举(在我的第一个函数之前),然后它告诉我同样的错误,但就在枚举声明之前。

error: "expected ';', identifier or '(' before 'void' void createCell(struct cell myCell, int type, int immutable)"

 #include <stdio.h>
#include "dungeon.h"
#define true 1
#define false 0
#define max_x 20
#define max_y 79


//why does it expect an identifier here?//
void createCell(struct cell myCell, int type, int immutable)
{
if(type == 0)
myCell.type = " ";

if(type == 1)
myCell.type = "#";

if(type == 2)
myCell.type = ".";

myCell.immutable = immutable;
}


void border_generator(struct cell cells[21][80]) {
int i, j;

for (i = 0; i < 21; i++) {
for(j = 0; j < 80; j++) {


if (i == 0 || i == max_x)
{
createCell(cells[i][j], 0, true);
printf("-");
}

else if( i > 0 && (j == 0 || j == max_y))
{
createCell(cells[i][j], 0, true);
printf("|");
}
else {
createCell(cells[i][j], 0, false);
printf("%c", cells[i][j].type);
}
if (j == max_y){
printf("\n");
}
}
}

}


void room_generator()
{


}


int main(int argc, char *argv[])
{
struct cell cells[21][80];
border_generator(cells);
return 0;
}

最佳答案

在“dungeon.h”的末尾,您有一个未以分号 (';') 终止的结构或 union 定义。

很容易重现同样的错误:

$ cat | cc -x c -
# 0 "dungeon.h"
struct foo { int x; }
# 3 "main.c"
void createCell(void){}
^D
main.c:3:1: error: expected ‘;’, identifier or ‘(’ before ‘void’

关于c - 在 ';' void createCell(struct cell myCell, int type, int immutable) 之前,我一直期望 '('、标识符或 'void',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52137105/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com