1

对于一个非常具体的项目,我需要用 C 语言编写一个 16 位程序,并且我在 MS-DOS 中使用 Microsoft QuickC 来编写这个程序。现在我很确定我的程序的语法是正确的,但是程序无法编译并且它认为我有语法错误。这是因为 MS-DOS 中的 C 编译器使用具有不同语法的旧版 C 吗?

#include<stdio.h>

main()
{
   printf("Hello World!");
}

即使是那个简单的 hello world 程序也无法编译和运行。

4

2 回答 2

3

您应该将 main 定义为 int

所以将您的代码更改为:

  int main() {    // define main as an int returning function

       // your code

       return 0; // Also make sure you have return statement in main
  }

它会编译

这是标准中所说的:

1 程序启动时调用的函数名为main。实现没有声明这个函数的原型。它应定义为返回类型int

int main(void) { /* ... */ } 

编辑:

好的,从您的评论中..您现在收到此错误:

   C1024: cannot open include file 'stdio.h'

这是微软的原因和解决方案:

http://support.microsoft.com/kb/97809

于 2013-11-04T07:55:59.123 回答
-1

就此而言,您不能省略 functionmain或任何其他 C 函数的类型。所以你要

void main() { ... }

或者

int main(int argc, char **argv) { ... }

尽管对于后者,编译器通常会要求您返回一个值。

于 2013-11-04T07:58:57.317 回答