2012-04-16 101 views
3

我有在C简单的代码:为什么我的.c编码不能在GCC中编译?

#include <stdio.h> 

main() 
{ 
    printf(“Hello, world! /n”); 
} 

,但我不能在GCC编译它。当我尝试编译它时发出警告:

1. gcc hello.c -o hello 
2. hello.c: In function 'main: 
3. hello.c:4:1: error: stray '\342' in program 
4. hello.c:4:1: error: stray '\200' in program 
5. hello.c:4:1: error: stray '\234' in program 
6. hello.c:4:11: error: 'Hello' undeclared (first use in this function) 
7. hello.c:4:11: note: each undeclared identifier is reported only once for each function 
    it appears in 
8. hello.c:4:18: error: 'world' undeclared (first use in this function) 
9. hello.c:4:23: error: expected ')' before '!' token 
10. hello.c:4:23: error: stray '\342' in program 
11. hello.c:4:23: error: stray '\200' in program 
12. hello.c:4:23: error: stray '\235' in program 

任何人都可以帮助我吗?

+3

你在你的代码具有智能引号(注意的'“'“卷曲”)。 – birryree 2012-04-16 04:20:37

+0

是这些报价,常规报价? – 2012-04-16 04:23:36

+0

您的文件使用UTF-8;序列''\ 342'',''200',''\ 234''映射到十六进制0xE2,0x80,0x9C,这是U + 201C的UTF-8编码左双引号MARK。结尾为''\ 235''的序列为U + 201D右侧双引号。不要使用一个文字处理器,它认为它应该在C中编码时将'''映射到这些标记中;它会驱使你疯狂。 – 2012-06-10 14:27:59

回答

13

您会收到这些错误,因为您大概从格式化的源复制并粘贴了该代码。 "不一样。将它们更改为该代码并编译。

你或许应该也跟随其主要的定义为约定:

int main(void) 

,因此返回一个int

+0

好的。我会试试看。无论如何感谢 。 :) – sintakartika 2012-04-16 04:20:46

4

你可能也想改变/ N为\ n