c - 错误: expected identifier or ‘(’ before ‘}’ token

标签 c compilation

我正在为一款名为 MTG(万智牌)的游戏制作一个小型的生命和毒物计数器,我遇到了一些无法编译的问题,有人可以帮忙吗?抱歉,如果它们很简单,我是 C 新手......

#include <stdio.h>
#include <stdlib.h>

int life = 20;
int poison = 0;
int amount;
char pn;
char lp;

int main(int argc, char* argv[]) {

while(1){
system("clear");
printf("Life:%d\nPoison Counters:%d\n\n\n", life, poison);
printf("\n\n<Life or Poison>(l/p) <positive or negative>(+/-) <amount>(#)\n\n\n>>>");
scanf("\n\n%c %c %d", &lp, &pn, &amount);
if(lp == 'l'){
    if(pn == '+'){
    life = life + amount;
    }
    else{
    life = life - amount;
    }
}else if(lp == 'p'){
    if(pn == '+'){
    poison = poison + amount;
    }
    else{
    poison = poison - amount;
    }
}else if(lp == 'q'){
break;
}
}
}
    }
return 0;
}

这就是终端告诉我的......

mtglife.c:36:2: error: expected identifier or ‘(’ before ‘}’ token
mtglife.c:37:1: error: expected identifier or ‘(’ before ‘return’
mtglife.c:38:1: error: expected identifier or ‘(’ before ‘}’ token

最佳答案

您没有正确关闭主函数。

#include <stdio.h>
#include <stdlib.h>

int life = 20;
int poison = 0;
int amount;
char pn;
char lp;

int main(int argc, char* argv[]) {

    while(1){
        system("clear");
        printf("Life:%d\nPoison Counters:%d\n\n\n", life, poison);
        printf("\n\n<Life or Poison>(l/p) <positive or negative>(+/-) <amount>(#)\n\n\n>>>");
        scanf("\n\n%c %c %d", &lp, &pn, &amount);
        if(lp == 'l'){
            if(pn == '+'){
                life = life + amount;
            }
            else{
                life = life - amount;
            }
        }else if(lp == 'p'){
            if(pn == '+'){
                poison = poison + amount;
            }
            else{
                poison = poison - amount;
            }
        }else if(lp == 'q'){
            break;
        }
    }
    return 0;
}

关于c - 错误: expected identifier or ‘(’ before ‘}’ token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24346965/

相关文章:

整数数组的 C While 循环

R:multicool 编译失败

c++ - 我用 Xcode 4 开发的 C++ 项目的编译问题

compilation - NVIDIA CUDA SDK示例编译不支持的体系结构 'compute_20'

c - 如何排除 Asterisk 的套接字连接故障

c - 是否需要创建指向结构的指针数组?

c - 在 C 中,你是否应该始终使用 'int' 作为数字,即使它们是非负数?

c++ - 为什么这两个值在arduino上不相等?

javascript - 为 Raspberry Pi 构建 Node.js 发生了什么

c++ - 预链接错误 : prelink-cross: simple hello world example