2012-04-16 112 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

相關問題