我正在编写一个基于文本的冒险游戏,以改进编码,我用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");
}
答案 0 :(得分:0)
尝试将每个函数的定义移动到它所调用的行之上,如下所示:
#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