- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是 C 的新手,我制作这个游戏只是为了练习我已经知道的东西。我不太明白如何使代码从一个函数转到另一个函数(也许称为调用函数?)。我已经编译并测试了几次,但每次至少有一件事不起作用,我盲目地继续(可能不是一个好主意),现在我不能继续了。还没完。
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int response;
int loyalty = 0;
int level = 1;
int howmany;
int dothemnow;
int squad1;
int responsetwo;
int pushup;
char name [20];
int main(){
pushup=1;
dothemnow=0;
howmany=0;
printf ("Welcome to Game1\n");
printf ("What's your name?\n");
scanf ("%s",name);
printf ("From now on you're Private %s\n",name);
printf ("Loading...\n");
sleep (2);
printf("You are in a army excersize yard.\n");
sleep (2);
printf("Your sargeant approaches.\n");
sleep (2);
printf ("Sargeant Sam: Drop and give me five, Private %s\n",name);
printf ("1)Yessir!\n2)Make me\n");
scanf ("%d", &response);
if(response==1){
while(howmany<4 && pushup==1){
printf ("You do a pushup.\n");
howmany ++;
sleep(1);
printf ("You have done %d pushups\n",howmany);
printf ("Do another?\n1) yes\n2) no\n");
scanf ("%d",&pushup);
}
}
if(howmany==5){
/*Make it so it goes to the war function*/
int war();
}
if(pushup==2 && dothemnow!=2){
dothemnow ++;
printf("Sargeant Sam: Do them NOW!!!\n");
sleep(2);
printf ("1)Why?\n2)Ok,ok\n");
scanf ("%d",&responsetwo);
}
if(responsetwo==1){
while(howmany<4 && pushup==1){
printf ("You do a pushup.\n");
howmany ++;
sleep(1);
printf ("You have done %d pushups\n",howmany);
printf ("Do another?\n1) yes\n2) no\n");
scanf ("%d",&pushup);
}
}
if(howmany==5){
int war();
}
if(pushup==2){
dothemnow ++;
}
if(responsetwo==2){
while(howmany<4 && pushup==1){
printf ("You do a pushup.\n");
howmany ++;
sleep(1);
printf ("You have done %d pushups\n",howmany);
printf ("Do another?\n1) yes\n2) no\n");
scanf ("%d",&pushup);
}
}
if(howmany==5){
int war();
}
if(pushup==2){
dothemnow ++;
}
if(response==2){
dothemnow ++;
printf("Sargeant Sam: Do them NOW!!!\n");
sleep(2);
printf ("1)Why?\n2)Ok,ok\n");
scanf ("%d",&responsetwo);
}
if(responsetwo==1){
dothemnow ++;
}
if(responsetwo==2)
while(howmany<4 && pushup==1){
printf ("You do a pushup.\n");
howmany ++;
sleep(1);
printf ("You have done %d pushups\n",howmany);
printf ("Do another?\n1) yes\n2) no\n");
scanf ("%d",&pushup);
if(pushup==2){
dothemnow ++;
}
if(howmany==5){
int war();
}
}
if(dothemnow==2){
printf ("You are under military arrest!\n");
}
return 0;
}
int war(){
printf ("Loading...");
sleep (2);
printf ("Seargant Sam: Great job Private %s.\n",name);
sleep (2);
printf ("You are hereby promoted to Corporal");
sleep (2);
printf ("****LEVEL UP!****\n");
sleep (1);
level ++;
printf ("You are now level %d!\n",level);
sleep (1);
printf ("Do you want to be friendly or strict to your squad?\n1) Friendly\n2) Strict\n");
scan("%d", squad1);
if(squad1==1){
loyalty --;
}
if(squad1==2)
loyalty ++;
}
printf ("Seargant Sam: You will be deployed to Afganistan in one week, Corporal %s.\n",name);
sleep (1);
printf ("In the mean time, get to know your sqaud.\n");
sleep (1);
printf ("There are ten about 20 to 25 year olds in front of you\n");
sleep (1);
printf ("1)Nod\n2)'Laugh' Well I guess I'm the boss of you now\n3)Salute\n4)Drop and give me twenty!\n");
scanf ("%d", &squad2);
switch(squad2){
case 1:
printf ("They nod back");
case 2:
loyalty - 2;
printf ("They all smile and laugh a little");
break;
case 3:
loyalty + 2;
printf ("They all salute back");
sleep(1)
printf ("'As you were', you say");
break;
case 4:
loyalty + 3;
printf ("They do the pushups");
break;
}
printf ("Seargant Sam: Show them to their cabin, Corporal.");
sleep (1);
printf("You walk to the cabin.\n");
sleep (1);
if(loyalty>0){
printf ("One of the soldiers in your squad, Private Smith, who looks wiry but strong, says 'Corporal, you seem like a cool guy, but how did you get promoted to corporal?'");
sleep (1);
printf ("Ha, I see how you could be confused");
sleep (1);
printf ("Well, I don't really know either, I just did five pushups, and wahla, Corporal.");
}
}
所以,当我尝试编译它时,我得到了错误:
game1.c:136: error: expected declaration specifiers or ‘...’ before string constant
game1.c:136: error: expected declaration specifiers or ‘...’ before ‘name’
game1.c:136: warning: data definition has no type or storage class
game1.c:136: error: conflicting types for ‘printf’
game1.c:136: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:137: error: expected declaration specifiers or ‘...’ before numeric constant
game1.c:137: warning: data definition has no type or storage class
game1.c:138: error: expected declaration specifiers or ‘...’ before string constant
game1.c:138: warning: data definition has no type or storage class
game1.c:138: error: conflicting types for ‘printf’
game1.c:138: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:139: error: expected declaration specifiers or ‘...’ before numeric constant
game1.c:139: warning: data definition has no type or storage class
game1.c:140: error: expected declaration specifiers or ‘...’ before string constant
game1.c:140: warning: data definition has no type or storage class
game1.c:140: error: conflicting types for ‘printf’
game1.c:140: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:141: error: expected declaration specifiers or ‘...’ before numeric constant
game1.c:141: warning: data definition has no type or storage class
game1.c:142: error: expected declaration specifiers or ‘...’ before string constant
game1.c:142: warning: data definition has no type or storage class
game1.c:142: error: conflicting types for ‘printf’
game1.c:142: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:143: error: expected declaration specifiers or ‘...’ before string constant
game1.c:143: error: expected declaration specifiers or ‘...’ before ‘&’ token
game1.c:143: warning: data definition has no type or storage class
game1.c:143: error: conflicting types for ‘scanf’
game1.c:143: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:144: error: expected identifier or ‘(’ before ‘switch’
game1.c:166: error: expected declaration specifiers or ‘...’ before string constant
game1.c:166: warning: data definition has no type or storage class
game1.c:166: error: conflicting types for ‘printf’
game1.c:166: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:167: error: expected declaration specifiers or ‘...’ before numeric constant
game1.c:167: warning: data definition has no type or storage class
game1.c:168: error: expected declaration specifiers or ‘...’ before string constant
game1.c:168: warning: data definition has no type or storage class
game1.c:168: error: conflicting types for ‘printf’
game1.c:168: note: a parameter list with an ellipsis can’t match an empty parameter name list declaration
game1.c:169: error: expected declaration specifiers or ‘...’ before numeric constant
game1.c:169: warning: data definition has no type or storage class
game1.c:170: error: expected identifier or ‘(’ before ‘if’
game1.c:181: error: expected identifier or ‘(’ before ‘}’ token
注意 is 并不是说它在函数 war 中。
最佳答案
你的问题在这里:
if(squad1==2)
loyalty ++;
}
您有右大括号,但没有左大括号。这个简单的语法错误导致了从这一点到文件末尾的一波编译错误。
请注意,第 136 行是第一个报告语法错误的地方,紧接在上述代码段之后。
关于c - 如何在C中调用一个函数?另外,为什么几乎每一行代码都是错误的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18048634/
为了让我的代码几乎完全用 Jquery 编写,我想用 Jquery 重写 AJAX 调用。 这是从网页到 Tomcat servlet 的调用。 我目前情况的类似代码: var http = new
我想使用 JNI 从 Java 调用 C 函数。在 C 函数中,我想创建一个 JVM 并调用一些 Java 对象。当我尝试创建 JVM 时,JNI_CreateJavaVM 返回 -1。 所以,我想知
环顾四周,我发现从 HTML 调用 Javascript 函数的最佳方法是将函数本身放在 HTML 中,而不是外部 Javascript 文件。所以我一直在网上四处寻找,找到了一些简短的教程,我可以根
我有这个组件: import {Component} from 'angular2/core'; import {UserServices} from '../services/UserService
我正在尝试用 C 实现一个简单的 OpenSSL 客户端/服务器模型,并且对 BIO_* 调用的使用感到好奇,与原始 SSL_* 调用相比,它允许一些不错的功能。 我对此比较陌生,所以我可能会完全错误
我正在处理有关异步调用的难题: 一个 JQuery 函数在用户点击时执行,然后调用一个 php 文件来检查用户输入是否与数据库中已有的信息重叠。如果是这样,则应提示用户确认是否要继续或取消,如果他单击
我有以下类(class)。 public Task { public static Task getInstance(String taskName) { return new
嘿,我正在构建一个小游戏,我正在通过制作一个数字 vector 来创建关卡,该数字 vector 通过枚举与 1-4 种颜色相关联。问题是循环(在 Simon::loadChallenge 中)我将颜
我有一个java spring boot api(数据接收器),客户端调用它来保存一些数据。一旦我完成了数据的持久化,我想进行另一个 api 调用(应该处理持久化的数据 - 数据聚合器),它应该自行异
首先,这涉及桌面应用程序而不是 ASP .Net 应用程序。 我已经为我的项目添加了一个 Web 引用,并构建了各种数据对象,例如 PayerInfo、Address 和 CreditCard。但问题
我如何告诉 FAKE 编译 .fs文件使用 fsc ? 解释如何传递参数的奖励积分,如 -a和 -target:dll . 编辑:我应该澄清一下,我正在尝试在没有 MSBuild/xbuild/.sl
我使用下划线模板配置了一个简单的主干模型和 View 。两个单独的 API 使用完全相同的配置。 API 1 按预期工作。 要重现该问题,请注释掉 API 1 的 URL,并取消注释 API 2 的
我不确定什么是更好的做法或更现实的做法。我希望从头开始创建目录系统,但不确定最佳方法是什么。 我想我在需要显示信息时使用对象,例如 info.php?id=100。有这样的代码用于显示 Game.cl
from datetime import timedelta class A: def __abs__(self): return -self class B1(A):
我在操作此生命游戏示例代码中的数组时遇到问题。 情况: “生命游戏”是约翰·康威发明的一种细胞自动化技术。它由一个细胞网格组成,这些细胞可以根据数学规则生存/死亡/繁殖。该网格中的活细胞和死细胞通过
如果我像这样调用 read() 来读取文件: unsigned char buf[512]; memset(buf, 0, sizeof(unsigned char) * 512); int fd;
我用 C 编写了一个简单的服务器,并希望调用它的功能与调用其他 C 守护程序的功能相同(例如使用 ./ftpd start 调用它并使用 ./ftpd stop 关闭该实例)。显然我遇到的问题是我不知
在 dos 中,当我粘贴此命令时它会起作用: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://google.
在 dos 中,当我粘贴此命令时它会起作用: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://google.
我希望能够从 cmd 在我的 Windows 10 计算机上调用 python3。 我已重新安装 Python3.7 以确保选择“添加到路径”选项,但仍无法调用 python3 并使 CMD 启动 P
我是一名优秀的程序员,十分优秀!