【问题标题】:error: expected identifier or '(' - c programming language错误:预期的标识符或 '(' - c 编程语言
【发布时间】:2017-06-10 00:09:10
【问题描述】:

几个小时以来,我一直在绞尽脑汁想弄清楚这一点。我收到以下代码的以下错误:

mario.c:5:1: 错误:预期标识符或'('

#include <cs50.h>
#include <stdio.h>

int main(void);

int blocks = 0;
do
{
    int blocks = get_int();
    printf("%d\n", blocks);
}
while (blocks > 23);

有人知道我在这里做错了什么吗?

【问题讨论】:

  • 尝试从int main(void); 行的末尾删除分号(;)

标签: cs50


【解决方案1】:

删除int main(void)声明后的;

int main(void)
{
    ...
}

【讨论】:

  • 这就是为什么我更喜欢将大括号与语句放在同一行的风格,我觉得这会使这个错误更难/更容易注意到。
  • @KarlReid,这可能是我听过的那种风格的最佳证明。比“我只是更喜欢它”好多了!
  • @fiveclubs 感谢您的提示。我摆脱了 ;在 int main(void) 之后但仍然出现类似错误:mario.c:7:1: error: expected identifier or '(' do ^ mario.c:12:1: error: expected identifier or '(' while (blocks > 23); ^
  • @TonyBalbin 看起来您取出了大括号而不是分号。应该是 int main(void) { ... 你所有的代码 ... }
  • 谢谢!工作。 :-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-19
  • 1970-01-01
相关资源
最近更新 更多