C语言编译错误: "expected declaration or statement at end of input"

如果你在编译C代码时遇到 "expected declaration or statement at end of input" 错误,通常是因为在代码的末尾缺少了一个声明或语句,或者存在语法错误,例如未封闭的括号。

错误提示示例:

../Core/Src/main.c:536:1: error: expected declaration or statement at end of input
  536 | }
      | ^
../Core/Src/main.c: In function 'main':
../Core/Src/main.c:536:1: error: expected declaration or statement at end of input

解决方法:

  1. 检查 main 函数的末尾: 确保在 main 函数的末尾添加了必要的声明或语句。
  2. 检查语法错误: 仔细检查代码,查找未封闭的括号、分号缺失或其他语法错误。

示例代码:

以下是一个示例,演示了如何在 main 函数中添加代码:

int main(void)
{
  // 在这里添加你的代码

  while (1)
  {
    // 在这里添加你的代码
  }

  // 确保在 main 函数结束前没有遗漏代码
}

根据你的代码逻辑,在 main 函数后面添加你需要的声明或语句,并仔细检查代码以确保没有语法错误。

解决C语言编译错误:

原文地址: https://www.cveoy.top/t/topic/hLa 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录