c - 编译c代码时出现奇怪的错误

标签 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;
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

最佳答案

您有一些语法错误 -

  • 除此之外,您的编辑器还包含 unicode 字符,而不是 gcc 期望的 ASCII。 - "作为后向双引号或前向双引号而不是 ASCII 34 的可能示例。

当您使用非西方字符集或扩展 unicode 作为默认编码时,必须小心编辑器设置。

这也是为什么 "字符不会出现在您的帖子中的原因。

关于c - 编译c代码时出现奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15048611/

上一篇:C 小于运算符

下一篇:c - c中的星星钻石

相关文章:

c++ - 模板参数阴影在 VS2005 中如何工作?

从 C 调用汇编函数

c++ - eclipse同步的C/C++项目同步失败

使用 MinGW32 GCC 编译。只告诉链接库一次?

gcc - gcc 链接器选项可以更改已编译二进制文件中的汇编器指令吗?

c++ - 在计算机上构建 RAPIDXML 库时遇到问题 - 错误消息

c - 将 float 分配给整数时无限循环

c - while 循环和静态变量

c - hh 和 h 格式说明符需要什么?

c++ - gcc not_fn 实现 : why does _Not_fn accept additional int parameter?