C 编译错误:在程序中杂散 '\200' 和预期的 ')' 之前的数字常量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18573008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C compile errors: stray '\200' in program and expected ')' before numeric constant
提问by Marc Howard
I copied this program and am having trouble with the void downFrequency function (I think). This is for Arduino Uno. Here are the compiler errors: Compiling 'MY_dds' for 'Arduino Uno'
我复制了这个程序,但在使用 void downFrequency 函数时遇到了问题(我认为)。这是针对 Arduino Uno 的。以下是编译器错误:为“Arduino Uno”编译“MY_dds”
MY_dds.ino : stray '2' in program
MY_dds.ino : stray '0' in program
MY_dds.ino : stray '3' in program
MY_dds.ino : stray '2' in program
MY_dds.ino : stray '0' in program
MY_dds.ino : stray '3' in program
MY_dds.ino : stray '2' in program
MY_dds.ino : stray '0' in program
MY_dds.ino : stray '3' in program
MY_dds.ino : stray '2' in program
MY_dds.ino : stray '0' in program
MY_dds.ino : stray '3' in program
MY_dds.ino : stray '2' in program
MY_dds.ino : stray '0' in program
MY_dds.ino : stray '3' in program
MY_dds.ino : stray '2' in program
MY_dds.ino : stray '0' in program
MY_dds.ino : stray '3' in program
MY_dds.ino : stray '2' in program
MY_dds.ino : stray '0' in program
MY_dds.ino : stray '3' in program
MY_dds.ino : stray '2' in program
MY_dds.ino : stray '0' in program
MY_dds.ino : stray '3' in program
MY_dds.ino : stray '2' in program
MY_dds.ino : stray '0' in program
MY_dds.ino : stray '3' in program
MY_dds.ino : : In function 'void downFrequency()':
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
MY_dds.ino : expected `)' before numeric constant
Error compiling
Here is the program:
这是程序:
#include <stdio.h>
#include <dds.h>
#include <LiquidCrystal.h>
#define RESET 13
#define data_pin 12
#define load_pin A5
#define clock_pin A4
#define clock_hz 120000000LL
#define calibrationValue -0.0400000 // this is a value we change to calibrate our particular chip more accurately
#define buttonPin A0
// chip, data_pin, load_pin, clock_pin, clock_hz
dds ddschip(DDS9850, data_pin, load_pin, clock_pin, clock_hz); // set my dds up with 120mhz onboard crystal
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// some variables to use in our program
long toFrequency = 14070000;
long currentFrequency;
long maxFrequency = 40000000;
long minFrequency = 0;
int incrementNumber = 6;
int maxprogramnumber = 6; // don't forget to increase the menu numbers here!!
int programnumber = 1;
void setup()
{
Serial.begin(9600);
Serial.println("Beginning Setup");
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("T.Robb V0.1b "); //Print a little message
lcd.setCursor(0, 1);
lcd.print(" DDS Sine wave ");
delay(2000);
// setup pins
pinMode(RESET, OUTPUT);
pinMode(data_pin, OUTPUT);
pinMode(load_pin, OUTPUT);
pinMode(clock_pin, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(buttonPin, HIGH);
ddschip.calibrate(calibrationValue); // this is a value we change to calibrate our particular chip more accurately
ddschip.setfrequency(toFrequency);
lcd.clear();
}
void loop()
{
if(toFrequency >= maxFrequency){(toFrequency = maxFrequency);}
if(toFrequency <= minFrequency){(toFrequency = minFrequency);}
ddschip.setfrequency(toFrequency);
currentFrequency = toFrequency;
switch(incrementNumber){
case 0:
Serial.println("increment amount is 1hz");
lcd.setCursor(0, 0);
lcd.print("Change By 1hz");
break;
case 1:
Serial.println("increment amount is 10hz");
lcd.setCursor(0, 0);
lcd.print("Change By 10hz ");
break;
case 2:
Serial.println("increment amount is 100hz");
lcd.setCursor(0, 0);
lcd.print("Change By 100hz ");
break;
case 3:
Serial.println("increment amount is 1 000hz");
lcd.setCursor(0, 0);
lcd.print("Change By 1khz");
break;
case 4:
Serial.println("increment amount is 10 000hz");
lcd.setCursor(0, 0);
lcd.print("Change By 10khz");
break;
case 5:
Serial.println("increment amount is 100 000hz");
lcd.setCursor(0, 0);
lcd.print("Change By 100khz");
break;
case 6:
Serial.println("increment amount is 1 000 000hz");
lcd.setCursor(0, 0);
lcd.print("Change By 1Mhz");
break;
default:
Serial.println("increment amount is 100hz");
lcd.setCursor(0, 0);
lcd.print("Change By 100hz ");
break;
}
lcd.setCursor(0, 1);
lcd.print("Freq is "); //Print to lcd
lcd.setCursor(8, 1);
lcd.print(currentFrequency);
Serial.println(incrementNumber); // temporary for debugging delete me
Serial.print("Current Frequency is set to :");
Serial.println(currentFrequency);
while((analogRead(buttonPin))>=1000){} // do nothing while no buttons pressed to chill out
delay(5);
if(analogRead(buttonPin)>=100 && analogRead(buttonPin)<=200){ // we have pushed up
upFrequency();
delay(300);
}
if(analogRead(buttonPin)>=200 && analogRead(buttonPin)<=400){ // we have pushed down
downFrequency();
delay(300);
}
if((analogRead(buttonPin))<=50){ // we have pushed right
incrementNumber++;
delay(300);
}
if(analogRead(buttonPin)>=400 && analogRead(buttonPin)<=600){ // we have pushed left
incrementNumber–;
delay(300);
}
if(incrementNumber > 6){incrementNumber = 0;} // this is where the menu goes around and around
if(incrementNumber < 0){incrementNumber = 6;}
delay(100);
lcd.clear();
}
void upFrequency()
{
Serial.println("Going UP Frequency");
switch(incrementNumber){
case 0:
toFrequency = (toFrequency + 1);
break;
case 1:
toFrequency = (toFrequency + 10);
break;
case 2:
toFrequency = (toFrequency + 100);
break;
case 3:
toFrequency = (toFrequency + 1000);
break;
case 4:
toFrequency = (toFrequency + 10000);
break;
case 5:
toFrequency = (toFrequency + 100000);
break;
case 6:
toFrequency = (toFrequency + 1000000);
break;
default:
toFrequency = (toFrequency + 10);
break;
}
}
void downFrequency()
{
Serial.println("Going DOWN Frequency");
switch(incrementNumber){
case 0:
toFrequency = (toFrequency – 1);
break;
case 1:
toFrequency = (toFrequency – 10);
break;
case 2:
toFrequency = (toFrequency – 100);
break;
case 3:
toFrequency = (toFrequency – 1000);
break;
case 4:
toFrequency = (toFrequency – 10000);
break;
case 5:
toFrequency = (toFrequency – 100000);
break;
case 6:
toFrequency = (toFrequency – 1000000);
break;
default:
toFrequency = (toFrequency – 10);
break;
}
}
回答by Mike Seymour
You've somehow ended up with "en dash" characters, rather than normal minus signs, in the downFrequencyfunction.
您以某种方式结束了downFrequency函数中的“破折号”字符,而不是正常的减号。
Make sure you're editing using a text editor, not a word processor; and for each of these:
确保您使用文本编辑器而不是文字处理器进行编辑;并且对于这些中的每一个:
toFrequency = (toFrequency – 1);
^
delete the marked character, and retype as a normal minus sign.
删除标记的字符,然后重新键入正常的减号。
(If you're interested in the gory details, the "dash" character is Unicode 2013, encoded in UTF-8 as three bytes with octal values 324,200,223, which is why you see those numbers in the error messages.)
(如果您对血腥细节感兴趣,“破折号”字符是Unicode 2013,以 UTF-8 编码为三个字节,八进制值为 324,200,223,这就是您在错误消息中看到这些数字的原因。)
回答by Potatoswatter
The compiler is complaining that there are non-ASCII characters in your source file.
编译器抱怨您的源文件中有非 ASCII 字符。
My octal fu is rusty, but it looks like UTF-8 to me. 342 200 223is E2 80 93which is Unicode "EN DASH." This code was given a minus sign makeover by a text editor with a degree in cosmetolegy.
我的八进制 fu 生锈了,但对我来说它看起来像 UTF-8。342 200 223是E2 80 93Unicode“EN DASH”。具有美容学位的文本编辑器对这段代码进行了减号改造。
回答by Siddhartha Ghosh
Probably your double quote symbols (") were wrong. Please check if they are actually ", and not ”.
可能您的双引号 (") 是错误的。请检查它们是否实际上是",而不是”。
回答by LinconFive
Simple copy always mess up the source code.
简单的复制总是弄乱源代码。
One can check the "stray" problem via cat -A yoursrc.c
可以通过以下方式检查“流浪”问题 cat -A yoursrc.c
To me, I usually reformat the code by vim in two steps.
对我来说,我通常分两步通过 vim 重新格式化代码。
vim yoursrc.c
:%!tr -cd '[:print:]\n'
Then compile gcc yoursrc.c
然后编译 gcc yoursrc.c

