【问题标题】:Expected declaration or statement at end of input. I counted the correct amount of brackets输入结束时的预期声明或声明。我计算了正确数量的括号
【发布时间】:2015-01-06 22:19:02
【问题描述】:

我在发布这个问题之前检查了互联网,我发现的答案是我可能缺少括号。

int main (void) {

int input = 0;

while(input != 3) {

    printf("Please select an implementation :"
            "\n1. Linked list implementation"
            "\n2. Ring buffer implementation"
            "\n3. Exit");

    fflush(stdout);
    scanf("%d",&input);

    switch(input) {

    case 1: printf("Linked List");
    break;

    case 2: printf("Ring Buffer");
    break;

    case 3: printf("Goodbye!");
    break;
    }
}


return 0;
}

我删除了案例中的所有代码以使其更短,但我仍然收到错误消息。更具体地说:

int main(void) { 的行我得到了错误

'main' is normally a non-static function [-Wmain]

在最后的} 行我收到错误:

expected declaration or statement at end of input

我尝试清理并刷新,再次构建项目,我还重新启动了计算机,但没有任何改变。

非常感谢!

【问题讨论】:

    标签: c switch-statement syntax-error main


    【解决方案1】:

    鉴于您的.c 文件是完美的,我以前见过这个,错误必须在您的一个标头(.h)文件中。

    【讨论】:

    • @iharob,这不会解决它。他自己的一个 .h 文件中有错误
    • 我有 #include stdio.h 哈哈 我会查看我的头文件非常感谢!
    • @user3160152:请更新您的问题以显示您的实际代码,包括任何#include 指令。
    【解决方案2】:

    您收到该错误的原因是您可能在其他文件中声明了 main,而编译器只希望它存在于您的 .c 文件中。您可能还需要考虑在 switch 语句中使用默认大小写。

    【讨论】:

      猜你喜欢
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 2017-01-26
      • 2021-02-09
      • 2018-06-12
      • 2019-01-19
      • 1970-01-01
      相关资源
      最近更新 更多