2013-02-24 204 views
-1

下面我有我試圖建立奇怪的錯誤編譯C代碼

#include stdio.h 
#include stdlib.h 
#include signal.h 
#include wiringPi.h 
#include softPwm.h 

void control_event(int sig); 
int HARD_PWM_PIN=1; Hardware PWM Pin(GPIO18-12) 
int SOFT_PWM_PIN=0; Software PWM Pin(GPIO0-11) 
int DELAY_MS=10; 
int main(void) 
{ 
    (void)signal(SIGINT,control_event); 
    (void)signal (SIGQUIT,control_event); 
    printf(Hardware and software based PWM test on LEDn); 
    if(getuid()!=0) wiringPi requires root privileges 
    { 
    printf(ErrorwiringPi must be run as root.n); 
    return 1; 
    } 
    if(wiringPiSetup()==-1) 
    { 
    printf(ErrorwiringPi setup failed.n); 
    return 1; 
    } 
    pinMode(HARD_PWM_PIN,PWM_OUTPUT); setup hardware pwm 
    softPwmCreate(SOFT_PWM_PIN,0,100); setup software pwm pin 
    int up; 
    int down; 
    while(1) 
    { 
    for(up=1;up=5;down--) 
    { 
     pwmWrite(HARD_PWM_PIN,down); 
     softPwmWrite(SOFT_PWM_PIN,down); 
     delay(DELAY_MS2); 
    } 
    delay(DELAY_MS5); 
    } 
} 
void control_event(int sig) 
{ 
    printf(bbExiting...n); 
    pwmWrite(HARD_PWM_PIN,0); 
    softPwmWrite(SOFT_PWM_PIN,0); 
    delay(100); wait a little for the pwm to finish write 
    exit(0); 
} 

的代碼,但我不斷收到以下錯誤,這只是其中的一部分,但他們幾乎始終與奇同符號和數字。

test1.c:20:1: error: stray â\302â in program 
test1.c:20:1: error: stray â\240â in program 
test1.c:21:1: error: stray â\302â in program 
test1.c:21:1: error: stray â\240â in program 
test1.c:22:1: error: stray â\302â in program 
test1.c:22:1: error: stray â\240â in program 
test1.c:23:1: error: stray â\302â in program 
test1.c:23:1: error: stray â\240â in program 
test1.c:23:1: error: stray â\302â in program 
test1.c:23:1: error: stray â\240â in program 
test1.c:24:1: error: stray â\302â in program 
test1.c:24:1: error: stray â\240â in program 
test1.c:24:1: error: stray â\302â in program 
test1.c:24:1: error: stray â\240â in program 
test1.c:25:1: error: stray â\302â in program 
test1.c:25:1: error: stray â\240â in program 
test1.c:26:1: error: stray â\302â in program 
test1.c:26:1: error: stray â\240â in program 
test1.c:26:38: error: unknown type name âsetupâ 
test1.c:26:53: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âpwmâ 

什麼可能是錯的?我從得到這個代碼的地方是here

+1

'int HARD_PWM_PIN = 1;硬件PWM引腳(GPIO18-12)'這幾乎不正確的C語法...是'硬件pwm引腳...'是否可以作爲註釋?在這種情況下缺少'//'。 – 2013-02-24 04:23:29

+2

你可能使用了一個文字處理器,並用'雙引號'代替ASCII雙引號。不是很好。你#include行不符合任何一種標準格式。 – 2013-02-24 04:30:09

回答

3

你有一些語法錯誤 -

    從您的編輯器包括Unicode字符,而不是由海灣合作委員會預計ASCII
  • 擱置。 - 對於「一個可能的例子作爲一個落後的雙引號或向前雙引號,而不是ASCII 34

你必須要小心你的編輯器設置時,您使用非西方字符集或擴展的Unicode爲您默認編碼

這也是爲什麼「字符不顯示在您的文章。

3

奇怪的符號和數字是因爲文件中的一些空格實際上不是空格。縱觀一些在你的鏈接文件中的行,複製和粘貼後:

'void control_event(int sig);\n' 
'int HARD_PWM_PIN=1; //Hardware PWM Pin(GPIO18-12)\n' 
'int SOFT_PWM_PIN=0; //Software PWM Pin(GPIO0-11)\n' 
'int DELAY_MS=10;\n' 
'int main(void)\n' 
'{\n' 
'\xc2\xa0 (void)signal(SIGINT,control_event);\n' 
'\xc2\xa0 (void)signal (SIGQUIT,control_event);\n' 
'\xc2\xa0 printf("Hardware and software based PWM test on LED\\n");\n' 
'\xc2\xa0 if(getuid()!=0) //wiringPi requires root privileges\n' 

那些\xc2\xa0 s爲無間斷空格字符( ),或八進制302/240

另請注意,您似乎在傳輸過程中丟失了多個註釋標記(//),因爲編譯器試圖將註釋解釋爲代碼,這導致了其自身的不同問題。