简体   繁体   English

原来的C你好,来自Kernighan和Ritchie的世界节目没有编译

[英]Original C hello, world program from Kernighan and Ritchie not compiling

I'm trying to learn C using the Kernighan and Ritchie book (The C Bible). 我正在尝试使用Kernighan和Ritchie的书(The C Bible)来学习C. Upon trying to compile the first problem using tcc and MinGW (using Windows). 尝试使用tcc和MinGW(使用Windows)编译第一个问题。 It gave me an error message. 它给了我一个错误信息。 The most detailed one came from Min GW: helloworld.c:3:8: error: expected ')' before '(' token 最详细的一个来自Min GW:helloworld.c:3:8:错误:预期')'之前'('令牌

Here is my program: 这是我的计划:

main()

(

    printf("hello, world\n");

)

As far as I can tell it follows the book to the dot. 据我所知,按照这本书来说。 Is this now out of date? 这已经过时了吗? I've looked for this and still can't find what I've done wrong. 我已经找到了这个但仍然找不到我做错了什么。 Please help. 请帮忙。

Thanks in advance! 提前致谢!

( blahblah; ) is not the same as { blahblah; } ( blahblah; ){ blahblah; } { blahblah; } , and your book might be a bit outdated (though the code should be fine to learn from, even if some requires changes). { blahblah; } ,和你的书可能是有点过时(尽管代码应罚款从学习,即使一些需要改变)。 Current standard C would be 目前的标准C是

#include <stdio.h>
int main(void)
{
    printf("hello, world\n");
    return 0;
}

main(void) could also be main(int argc, char *argv[]) if you want to read command line arguments. 如果你想读取命令行参数main(int argc, char *argv[]) main(void)也可以是main(int argc, char *argv[])

You are mistakenly using ( and ) instead of { and } . 您错误地使用()而不是{} And presumably the code in the book has a #include statement in order to declare printf . 并且可能是本书中的代码有一个#include语句来声明printf

You used parentheses instead of brackets. 您使用括号而不是括号。 It should be 它应该是

#include <stdio.h>

main() {
    printf("hello, world\n");
}

The symbols that begin and end a function's body are curly braces, not parentheses. 开始和结束函数体的符号是花括号,而不是括号。 It should look like: 它应该看起来像:

main()
{
    printf("hello, world\n");
}

That said, this is indeed woefully out of date. 这就是说,这确实是可悲过时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM