gcc not working correctly

Asked by Moonstroller

I'm conpiling a hello world c program:
#include <stdio.h>
int main(void)
{
     fprintf(stdout, “Hello, Linux programming world!\n”);
     return 0;
}
When I run gcc hello.c -o hello I get the following output:

moonstroller@moonstroller-laptop:~/Documents$ gcc hello.c -o hello
hello.c: In function ‘main’:
hello.c:4: error: stray ‘\342’ in program
hello.c:4: error: stray ‘\200’ in program
hello.c:4: error: stray ‘\234’ in program
hello.c:4: error: ‘Hello’ undeclared (first use in this function)
hello.c:4: error: (Each undeclared identifier is reported only once
hello.c:4: error: for each function it appears in.)
hello.c:4: error: ‘Linux’ undeclared (first use in this function)
hello.c:4: error: expected ‘)’ before ‘programming’
hello.c:4: error: stray ‘\’ in program
hello.c:4: error: stray ‘\342’ in program
hello.c:4: error: stray ‘\200’ in program
hello.c:4: error: stray ‘\235’ in program

I did a sudo apt-get install build-essential and rebooted laptop but it is still not working.

I'm lost at this point.

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gcc-defaults Edit question
Assignee:
No assignee Edit question
Solved by:
Moonstroller
Solved:
Last query:
Last reply:
Revision history for this message
Philip Wyett (philwyett) said :
#1

At a guess this is a copy and paste from a book and the " and \ are wrong set. Remove and type the line in manually and try recompiling.

Revision history for this message
Mark Rijckenberg (markrijckenberg) said :
#2

Hi,

If you compare the hello world program from http://en.wikipedia.org/wiki/C_(programming_language) with the code here, I see that you used the command fprintf instead of printf

Try replacing fprintf with printf in line 4.

Regards,

Mark

Revision history for this message
Moonstroller (moonstroller) said :
#3

I solved the problem by switching back to slackware.

I suspect that the problem was, as denoted by Mark Rijckenberg, changing fprintf to printf but I can't prove it now.

Thanks for the help.