0

My sample.c program:

#include <stdio.h>

int main()
{
    printf(“Hello, World!\n”);
    return 0;
}

When I want compile it, I see this error (as root):

cd ~/Desktop
x86_64-w64-mingw32-gcc sample.c -o file.exe

Output:

sample.c: In function ‘main’:
sample.c:5:2: error: stray ‘\342’ in program
sample.c:5:2: error: stray ‘\200’ in program
sample.c:5:2: error: stray ‘\234’ in program
sample.c:5:12: error: ‘Hello’ undeclared (first use in this function)
sample.c:5:12: note: each undeclared identifier is reported only once for each function it appears in
sample.c:5:18: error: expected ‘)’ before ‘World’
sample.c:5:18: error: stray ‘\’ in program

sample.c:5:18: error: stray ‘\342’ in program
sample.c:5:18: error: stray ‘\200’ in program
sample.c:5:18: error: stray ‘\235’ in program

I can't compile any C format file. How can I fix it?

Note: It cross compiles to Windows, thus "file.exe".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Danial Hosseini
  • 33
  • 1
  • 2
  • 9
  • 5
    Its those pesky smart quotes `“Hello World!\n”`. Use normal quotes`"`. – chux - Reinstate Monica Apr 02 '15 at 21:08
  • 2
    It is certainly a duplicate - just cannot find it fast. Maybe http://stackoverflow.com/q/19198332/2410359 or http://stackoverflow.com/questions/11334454/how-do-i-make-this-simple-shellcode-c-program-compile-from-terminal/11334478#11334478 – chux - Reinstate Monica Apr 02 '15 at 21:10
  • thanks bro I changed it but still it isn't compiled : root@Kali:~/Desktop# gcc sample.c -o file /tmp/cciJWsOr.o: In function `main': sample.c:(.text+0x11): undefined reference to `print' collect2: error: ld returned 1 exit status – Danial Hosseini Apr 02 '15 at 21:11
  • Hmmm "undefined reference to print" -- should not that be `printf` (missing f)? Suggest changing to a program editor. – chux - Reinstate Monica Apr 02 '15 at 21:13
  • Direct analysis: 342 200 234 (octal) → 0xE2 0x80 0x9C (hexadecimal) → UTF-8 sequence for Unicode code point U+201C ([LEFT DOUBLE QUOTATION MARK](https://www.charset.org/utf-8/9)). And 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)). They can be searched for (and replaced) with the regular expression `\x{201C}|\x{201D}` in any modern text editor or IDE (different notation in Visual Studio Code (and probably others): `\u201C|\u201D`). – Peter Mortensen Apr 28 '23 at 17:43
  • 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 17:45
  • It is the wrong close reason. It should be closed as a duplicate of a canonical question. – Peter Mortensen Apr 28 '23 at 17:46

1 Answers1

1

This is due to your editor. (quotation marks) and " is different and is causing the error. Try with ".

#include <stdio.h>

int main()
{
    printf(“Hello, World!\n”);
    return 0;
}

Try another code editor.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rahul K Jha
  • 788
  • 9
  • 18
  • Re *"This is due to your editor."*: Unlikely. It is much more likely it is caused by copying code from a web page or PDF document. – Peter Mortensen Apr 28 '23 at 17:39