3

I have some simple code in C:

#include <stdio.h>

main()
{
    printf(“Hello, World! /n”);
}

But I can't compile it in GCC. When I try to compile it, the warning is:

1. gcc hello.c -o hello
2. hello.c: In function 'main:
3. hello.c:4:1: error: stray '\342' in program
4. hello.c:4:1: error: stray '\200' in program
5. hello.c:4:1: error: stray '\234' in program
6. hello.c:4:11: error: 'Hello' undeclared (first use in this function)
7. hello.c:4:11: note: each undeclared identifier is reported only once for each function
   it appears in
8. hello.c:4:18: error: 'World' undeclared (first use in this function)
9. hello.c:4:23: error: expected ')' before '!' token
10. hello.c:4:23: error: stray '\342' in program
11. hello.c:4:23: error: stray '\200' in program
12. hello.c:4:23: error: stray '\235' in program

How can I fix it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sintakartika
  • 127
  • 3
  • 11
  • 4
    You have smart quotes in your code (notice the 'curliness' of the `"`). – wkl Apr 16 '12 at 04:20
  • Are those quotes, regular quotes ? – Niall Byrne Apr 16 '12 at 04:23
  • 1
    Your file is using UTF-8; the sequence `'\342'`, `'\200'`, `'\234'` maps to hex 0xE2, 0x80, 0x9C, which is the UTF-8 encoding of U+201C LEFT DOUBLE QUOTATION MARK. The sequence ending `'\235'` is U+201D RIGHT DOUBLE QUOTATION MARK. Don't use a word processor that thinks it should map `"` into these marks when coding in C; it will drive you bonkers. – Jonathan Leffler Jun 10 '12 at 14:27
  • 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 27 '23 at 18:18
  • The particular ones can be searched for (and replaced) in any modern editor or IDE by the regular expression `\x{201C}|\x{201D}` (in [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code) or some others, the notation is different: `\u201C|\u201D`) – Peter Mortensen Apr 27 '23 at 18:25
  • It is more than a warning. It is a compile error. – Peter Mortensen Apr 27 '23 at 18:35
  • You probably also want to change /n to \n – Nick Atoms Apr 16 '12 at 04:22

1 Answers1

13

You get those errors because you presumably copy and pasted that code from a formatted source. and aren't the same as ". Change them to that and the code will compile.

You should probably also follow the convention of having main defined as:

int main(void)

and therefore returning an int.

AusCBloke
  • 18,014
  • 6
  • 40
  • 44