Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编译c代码时的奇怪错误_C_Gcc - Fatal编程技术网

编译c代码时的奇怪错误

编译c代码时的奇怪错误,c,gcc,C,Gcc,我有下面的代码,我正试图建立 #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; i

我有下面的代码,我正试图建立

#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â

有什么不对劲吗?我获取此代码的地方是

您有一些语法错误-

  • 除此之外,您的编辑器包含unicode字符,而不是gcc所期望的ASCII字符。-一个可能的例子是“作为向后双引号或向前双引号而不是ASCII 34
当使用非西方字符集或扩展unicode作为默认编码时,必须小心编辑器设置


这也是为什么“字符不会出现在您的帖子中。”奇怪的符号和数字是因为文件中的一些空格实际上不是空格。复制和粘贴后,查看链接中文件中的某些行:

'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
是不间断空格字符(
),或八进制的
302/240


还要注意的是,您似乎在传输过程中丢失了几个注释标记(
/
),这导致了编译器试图将注释解释为代码时出现的不同问题。

int HARD\u PWM\u PIN=1;硬件PWM引脚(GPIO18-12)
这几乎不是正确的C语法。。。是否支持将
硬件pwm引脚…
作为注释?在这种情况下缺少一个
/
。您可能使用了文字处理器,并使用了“智能引号”代替ASCII双引号。这不好。您的
#include
行与两个标准表单都不匹配。