PDA

View Full Version : Error compiling simple code.



jessiebrownjr
October 3rd, 2009, 07:59 PM
This is basic C im attempting to learn.This is the code that Anjuta IDE pops out onto the screen when you make a new file as a template.

#include <stdio.h>
int main()
{
printf(''Goodbye, cruel world!\n'');
return(0);
}
Now that seems like it should compile right? I hit build, and get a slew of errors.

main.c:4:20: error: empty character constant
main.c: In function ‘main’:
main.c:4: error: expected ‘)’ before ‘Goodbye’
main.c:4: error: stray ‘\’ in program
main.c:4:45: error: empty character constant
main.c:4: warning: null argument where non-null required (argument 1)
make: *** [main.o] Error 1I'm lost how I'm supposed to even start learning to program when even the basic code like this the compiler itself gave me to as a template isn't compiling.. what could possibly be wrong?

On another compiler when I tried to run a code that would be assumed to be proper, it would error out as well.

Please help if you can think of anything, this is very frustrating.

MadCow108
October 3rd, 2009, 08:09 PM
you have two ' (single apostrophes) resulting in '' instead of a " (double apostrophe or however this calls in English)
looks similar but its not :)
syntax highlighting should also show you that
replace the '' by " and see the difference

wmcbrine
October 3rd, 2009, 08:12 PM
You've got a pair of single quote marks at each end of the string. It needs to be one, double quote mark character at each end.

Can+~
October 3rd, 2009, 08:19 PM
C reserves single quotes for character types, and double quotes for strings.

"Hello World" = 'H' 'e' 'l' 'l' 'o' ' ' 'W' 'o' 'r' 'l' 'd' 0

jessiebrownjr
October 3rd, 2009, 09:06 PM
I repalced it with the double quotes and it worked.... Now WTF did the "anjuta ide" come with a bad default program? silly. Thanks guys

phrostbyte
October 3rd, 2009, 09:42 PM
You can also do

return 0;

for future reference, the parenthesis are pretty pointless

Typically you return a value from main() other then zero when there is an fatal error

if (error) return -1;

for instance.

jessiebrownjr
October 3rd, 2009, 10:01 PM
You can also do

return 0;

for future reference, the parenthesis are pretty pointless

Typically you return a value from main() other then zero when there is an fatal error

if (error) return -1;

for instance.

i'm sure this is great advice thats ahead of my time :-)

Now I have a new question.. I compiled the program finally and the only way I was able to go into a terminal and run it, was if I moved it to like my root dir with gksudu nautilus... now can I add my user desktop to where I can run my newbie compiled files from a local dir/desktop if I choose to?

Thanks for quick replies!

MadCow108
October 3rd, 2009, 10:27 PM
you probably tried to run it like that:
myprogram.o
this then searches for a file named myprogram.o in your $PATH environment variable (you can see that with echo $PATH) and probably didn't find it.

If the program lies in a path which is not in $PATH then you give a relative or absolute path to the program:
./myprogram.o
(. means current directory)

alternatively you can add the path where it lies in to the $PATH variable by typing this:
export PATH=$PATH:/some/dir
add this to your .bashrc to have this change permanently in the terminal

also note that when you want to start a terminal program by double clicking it it will close immediately after it finishes, so you won't see anything in most cases