【问题标题】:error: expected ';' before number constant错误:预期的';'在数字常数之前
【发布时间】:2018-10-05 16:24:36
【问题描述】:

我是编程新手,我正在努力学习,所以我想写点东西。 但是有这个错误说:预期的';' BEFORE 数字常量。 有谁知道为什么?谢谢。 正如我所说,我是编程新手,所以不要对我极其简单的代码感到惊讶:D

struct Country{
    char name[50];
    char capital[50];
    char statehead[50];
    int pop;
double area;
};

int main(){

    struct Country stat1;
    stat1.area = 78 866.2;
    stat1.pop = 10 560 000;
    strcpy( stat1.name, "Ceska republika");
    strcpy( stat1.capital, "Praha");
    strcpy( stat1.statehead, "MilosZeman");

    printf("%d", stat1.area);

    return 0;
}

【问题讨论】:

标签: c compiler-errors


【解决方案1】:

问题出在这里:

stat1.area = 78 866.2;
stat1.pop = 10 560 000;

数字不应包含空格,因此只需删除它们,代码即可编译。

如果您实际上是在编写 C++ 代码(版本 14 或更高版本),您可以使用数字分隔符(在 floating pointinteger 数字文字中)对它们进行分组,以便它们易于阅读:

stat1.area = 78'866.2;
stat1.pop = 10'560'000;

【讨论】:

  • 天哪,我没有注意到:D。非常感谢。
  • 如果您认为您的问题已得到解答,您可以通过单击旁边的复选标记来接受答案。这有助于其他人立即看到您不再在此问题上寻求帮助。 stackoverflow.com/help/someone-answers
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
相关资源
最近更新 更多