Why can't my .c encoding be compiled in GCC?

I have a simple code in c:

#include <stdio.h>

main()
{
   printf("Hello, world! /n");
}

but I can not compile it in GCC. Warning when I try to compile it:

 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

Can anybody help me?

+3
source share
2 answers

You get these errors because you are supposedly copying and pasting this code from a formatted source. "and "do not match with ". Change them to this and the code will be compiled.

You should probably also follow the convention that main is defined as:

int main(void)

and therefore returns int.

+13
source

You probably also want to change / n to \ n

+4
source

All Articles