gpt4 book ai didi

C错误: called object is not a function or function pointer

转载 作者:行者123 更新时间:2023-11-30 16:41:19 63 4
gpt4 key购买 nike

我正在编写一个基于文本的冒险游戏,以提高编码水平,并且我正在用 C 语言编写它,因为这是我在学校使用的语言。我不断收到错误 game.c:28:15: 错误:被调用的对象“room2”不是函数或函数指针。关于如何改进我的代码有什么建议吗?

#include <stdio.h>

int c;
void start(), begin(), room2();

int main(){
start();
return 0;
}

void start(){
printf("Welcome to the Adventure Game! Press s to start\n");
c = getchar();
if(c=='s'){begin();}
}

void begin(){
printf("Text here involving describing a room and directions the player can take, if they press n they will go north\n");
c = getchar();
if(c=='n'){room2();}/*This is where I get the error*/
}

void room2(){
printf("Describes room2 and the player's surroundings, etc\n");
}

最佳答案

尝试将每个函数的定义移动到调用它的行上方,如下所示:

#include <stdio.h>

int c;
void start(), begin(), room2();

void room2(){
printf("Describes room2 and the player's surroundings, etc\n");
}

void begin(){
printf("Text here involving describing a room and directions the player can take, if they press n they will go north\n");
c = getchar();
if(c=='n'){room2();}/*This is where I get the error*/
}

void start(){
printf("Welcome to the Adventure Game! Press s to start\n");
c = getchar();
if(c=='s'){begin();}
}

int main(){
start();
return 0;
}

将c更改为char仍有问题

关于C错误: called object is not a function or function pointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46291794/

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