I’m getting these errors in my program after pasting in some code:
showdata.cpp:66: error: stray ‘\342’ in program
showdata.cpp:66: error: stray ‘\200’ in program
showdata.cpp:66: error: stray ‘\235’ in program
showdata.cpp:66: error: stray ‘\’ in program
showdata.cpp:66: error: stray ‘\342’ in program
showdata.cpp:66: error: stray ‘\200’ in program
showdata.cpp:66: error: stray ‘\235’ in program
showdata.cpp:67: error: stray ‘\342’ in program
showdata.cpp:67: error: stray ‘\200’ in program
showdata.cpp:67: error: stray ‘\235’ in program
showdata.cpp:67: error: stray ‘\’ in program
showdata.cpp:67: error: stray ‘\342’ in program
showdata.cpp:67: error: stray ‘\200’ in program
showdata.cpp:67: error: stray ‘\235’ in program
Here are the two lines that are causing the errors.
size_t startpos = str.find_first_not_of(” \t”);
size_t endpos = str.find_last_not_of(” \t”);
How can I fix this?
asked Feb 26, 2010 at 10:35
neuromancerneuromancer
53.9k78 gold badges166 silver badges224 bronze badges
2
The symbol ”
is not "
. Those are called ‘smart quotes’ and are usually found in rich documents or blogs.
answered Feb 26, 2010 at 10:38
5
The lines
size_t startpos = str.find_first_not_of(” \t”);
size_t endpos = str.find_last_not_of(” \t”);
have some «special» kind of double quotes, try the following:
size_t startpos = str.find_first_not_of(" \t");
size_t endpos = str.find_last_not_of(" \t");
answered Feb 26, 2010 at 10:38
hlovdalhlovdal
26.6k10 gold badges94 silver badges166 bronze badges
This sort of error message, error: stray ‘\xyz’ in program
, can appear with any other character or symbol that is not recognized by the compiler as a legal one.
Sharing my personal experience:
- bool less<const char∗>(const char∗ a, const char∗ b)
- bool less<const char*>(const char* a, const char* b)
The former one is copy-pasted from a PDF file. It doesn’t compile.
The latter one compiles as expected.
answered Aug 31, 2017 at 11:12
Saurav SahuSaurav Sahu
13.1k6 gold badges65 silver badges79 bronze badges
0
You can use the sed command to fix these issues.
This will give you a quick preview of what will be replaced.
sed s/[”“]/'"'/g File.txt
This will do the replacements and put the replacement in a new file called WithoutSmartQuotes.txt.
sed s/[”“]/'"'/g File.txt > WithoutSmartQuotes.txt
This will overwrite the original file.
sed -i ".bk" s/[”“]/'"'/g File.txt
answered Nov 13, 2014 at 13:27
cokedudecokedude
3791 gold badge11 silver badges21 bronze badges
2
I’m getting these errors in my program after pasting in some code:
showdata.cpp:66: error: stray ‘\342’ in program
showdata.cpp:66: error: stray ‘\200’ in program
showdata.cpp:66: error: stray ‘\235’ in program
showdata.cpp:66: error: stray ‘\’ in program
showdata.cpp:66: error: stray ‘\342’ in program
showdata.cpp:66: error: stray ‘\200’ in program
showdata.cpp:66: error: stray ‘\235’ in program
showdata.cpp:67: error: stray ‘\342’ in program
showdata.cpp:67: error: stray ‘\200’ in program
showdata.cpp:67: error: stray ‘\235’ in program
showdata.cpp:67: error: stray ‘\’ in program
showdata.cpp:67: error: stray ‘\342’ in program
showdata.cpp:67: error: stray ‘\200’ in program
showdata.cpp:67: error: stray ‘\235’ in program
Here are the two lines that are causing the errors.
size_t startpos = str.find_first_not_of(” \t”);
size_t endpos = str.find_last_not_of(” \t”);
How can I fix this?
asked Feb 26, 2010 at 10:35
neuromancerneuromancer
53.9k78 gold badges166 silver badges224 bronze badges
2
The symbol ”
is not "
. Those are called ‘smart quotes’ and are usually found in rich documents or blogs.
answered Feb 26, 2010 at 10:38
5
The lines
size_t startpos = str.find_first_not_of(” \t”);
size_t endpos = str.find_last_not_of(” \t”);
have some «special» kind of double quotes, try the following:
size_t startpos = str.find_first_not_of(" \t");
size_t endpos = str.find_last_not_of(" \t");
answered Feb 26, 2010 at 10:38
hlovdalhlovdal
26.6k10 gold badges94 silver badges166 bronze badges
This sort of error message, error: stray ‘\xyz’ in program
, can appear with any other character or symbol that is not recognized by the compiler as a legal one.
Sharing my personal experience:
- bool less<const char∗>(const char∗ a, const char∗ b)
- bool less<const char*>(const char* a, const char* b)
The former one is copy-pasted from a PDF file. It doesn’t compile.
The latter one compiles as expected.
answered Aug 31, 2017 at 11:12
Saurav SahuSaurav Sahu
13.1k6 gold badges65 silver badges79 bronze badges
0
You can use the sed command to fix these issues.
This will give you a quick preview of what will be replaced.
sed s/[”“]/'"'/g File.txt
This will do the replacements and put the replacement in a new file called WithoutSmartQuotes.txt.
sed s/[”“]/'"'/g File.txt > WithoutSmartQuotes.txt
This will overwrite the original file.
sed -i ".bk" s/[”“]/'"'/g File.txt
answered Nov 13, 2014 at 13:27
cokedudecokedude
3791 gold badge11 silver badges21 bronze badges
2
You’re enclosing your string in the wrong kind of quotes.
You have:
“Hello World\n”
You should instead have:
"Hello World\n"
While the quotes you’ve used look similar, they are not recognized by a C compiler as enclosing a string. Thus, you get error messages about unrecognized Unicode characters, and you get error messages showing that the contents of the string are being interpreted as unquoted program code.
You will note that the quotes you’ve used have separate characters for beginning and ending a quotation (they are curved the way quotes are often typeset). Many word processors—as Jobin suggested—will automatically turn simple "
quotes into such fancy quotation marks. If you’re using a word processor to compose C programs, you should use a text editor instead.
Ubuntu comes with gedit
installed by default (though there are many other text editors to choose from, too). Like many text editors, gedit
provides syntax highlighting for many programming languages including C (so different text in your program will shown in different colors to signify its meaning), which is a handy feature and makes a text editor much more convenient and user-friendly for programming than a word processor.
This might be Ubuntu-specific, if you’re used to a text editor on another platform that automatically reduces pasted quotations marks to the non-fancy version. But this question might end up getting closed and migrated to Stack Overflow.
Loading
Offline
Зарегистрирован: 19.12.2020
Всем привет . Проблема с инициализацией дисплея nokia 5110. Взял скетч с инета для проверки . А компилятор выдал ошибку 342. Что это за ошибка я не смог найти . Прошу помочь. Вот скетч.
#include <LCD5110_Graph.h> #include <LCD5110_Basic.h> LCD5110 LCD(7, 6, 5, 4, 3); //обьявляем дисплей с указанием пинов подключения extern uint8_t SmallFont[]; //указываем наличие массива со шрифтом SmallFont в библиотеке extern uint8_t MediumNumbers []; //указываем наличие массива со шрифтом MediumNumbers в библиотеке void setup() { LCD.InitLCD(); //инициализируем дисплей } void loop() { LCD.disableSleep(); //выводим дисплей из режима сна LCD.clrScr(); //очищаем дисплей LCD.setFont(SmallFont); //устанавливаем шрифт SmallFont LCD.print(“Hello World!”, CENTER, 2); //выводим “Hello World!” на второй строчке с равнением по центру LCD.setFont(MediumNumbers); // устанавливаем шрифт MediumNumbers for (int i=0; i<=5; i++) { LCD.clrScr(); //очищаем экран LCD.print(i, CENTER, 20); //выводим значение i по центру 20 строчки delay(1000); } LCD.enableSleep(); //вводим дисплей в режим сна на время длительной паузы delay(5000);