简体   繁体   English

C错误:被调用的对象不是函数或函数指针

[英]C Error: called object is not a function or function pointer

I'm writing a text-based adventure game to improve at coding, and I'm writing it in C since that's what I'm using at school. 我正在写一个基于文本的冒险游戏,以改进编码,并且我正在用C编写它,因为那是我在学校使用的东西。 I keep getting the error game.c:28:15: error: called object 'room2' is not a function or function pointer. 我不断收到错误game.c:28:15:错误:称为对象“ room2”不是函数或函数指针。 Any tips for how I can improve my code? 关于如何改进代码的任何提示?

#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");
}

try to move the difinition of each function to be above the line where it is called like this: 尝试将每个函数的定义移动到这样调用的行上方:

#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;
}

still have a problem change c into char 仍然有问题将c更改为char

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM