How to fix compilation errors that mention "stray ‘\342’" and "stray ‘\200’"? [closed]
Solution 1:
The problem is that you have Unicode quotation marks instead of ASCII quotation marks; probably your editor automatically changed them, or you copied the text from a site that does this automatically in its authoring software. Replace the quotes with normal ASCII quote (0x22, ") and it should work.
Fixed source:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
Solution 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.
Solution 3:
You can use the sed
command to fix these issues.
This will give you a quick preview of what will be replaced.
sed -re 's/”|“/"/g' File.txt
This will do the replacements and put the replacement in a new file called WithoutSmartQuotes.txt
:
sed -re 's/”|“/"/g' File.txt > WithoutSmartQuotes.txt
This will overwrite the original file:
sed -i .bk -re 's/”|“/"/g' File.txt