2

I'm trying to write a simply Hello, World! program, but when attempting to compile with GCC, I receive the following error:

helloworld.c:5:18: error: expected ‘)’ before ‘World’
  printf(“Hello World”);
                  ^
helloworld.c:5:18: error: stray ‘\342’ in program
helloworld.c:5:18: error: stray ‘\200’ in program
helloworld.c:5:18: error: stray ‘\235’ in program

Why is this?

Compiler: GCC 4.8.4 (2014-12-19). OS: Ubuntu 14.04 (Trusty Tahr).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Monty123
  • 103
  • 1
  • 7
  • 4
    If your source really has curly quotes around `“Hello World”`, C can't understand them. Use typewriter-style straight quotes, ASCII code 34: `"Hello World"`. If your editor converts pairs of straight quotes to curly quotes, turn that option off. – M Oehm Sep 17 '15 at 13:17
  • you will find `geany` and `gedit` to be MUCH better for editing code than using a word processor like `libre` . (and in geany, you can set the compile and build menu items to use gcc with all the desirable parameters, so you only have to enter it once and it will be good 'forever' – user3629249 Sep 19 '15 at 07:23
  • Direct analysis: 342 200 235 (octal) → 0xE2 0x80 0x9D (hexadecimal) → UTF-8 sequence for Unicode code point U+201D ([RIGHT DOUBLE QUOTATION MARK](https://www.charset.org/utf-8/9)). – Peter Mortensen Apr 28 '23 at 16:38
  • There is probably also an error triplet for the other quote: \342 \200 \234 (U+201C ([LEFT DOUBLE QUOTATION MARK](https://www.charset.org/utf-8/9))). It must have been the first error. Why was it left out? – Peter Mortensen Apr 28 '23 at 16:40
  • This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Apr 28 '23 at 16:41

2 Answers2

5
printf(“Hello World”);

This should be written as -

printf("Hello World");

Straight quotes should be used. Try changing style .

ameyCU
  • 16,489
  • 2
  • 26
  • 41
4

The octal sequence 342 200 234 is the UTF-8 byte sequence for the typographic double quote.

To fix it, replace it with the regular double quote, i.e. " instead of .

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Codo
  • 75,595
  • 17
  • 168
  • 206