Question:
Why can't I even get "Hello, World!" to run right?
jwhite1979
2009-05-07 11:26:39 UTC
So I'm all ready to start learning C. I have a book. I downloaded Dev-C++. It's installed, and I type the source code just as I see it:
#include

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

I run it through the compiler and run the program. Nothing. A little window--looks like a DOS prompt--pops up and disappears before I can see if anything is written there.

What am I doing wrong? Could it be a setting on the compiler? Could it not be linking the way it should?
Five answers:
femtorgon2
2009-05-07 11:35:45 UTC
That's do be expected, and it is working correctly. You need to pause the program so that it doesn't automatically close the console as soon as the program completes execution:

#include

int main(void)

{

printf("Hello, World!\n");

getchar(); /*wait for the user to input something (or just press enter) to finish*/

return 0;

}





Another way to deal with this, is use the program as you have it, and run from the command line (start -> run -> cmd).



EDIT:

As far as a compiler, there is always g++ (the GNU C++ compier). If you're on Linux, that's probably already there for you. Otherwise, you can use it through Cygwin:

http://www.cygwin.com/

Which can also get you vi and emacs, which are both very good text editors.

Also, here's another nice text editor to take a look it (this one with a GUI unlike vi or emacs), Notepad++:

http://notepad-plus.sourceforge.net/uk/site.htm

I think you might find it a lot nicer than textpad for writing code (since that's what notepad++ is designed for)
anonymous
2014-10-12 22:23:54 UTC
Why can't I even get "Hello, World!" to run right?



So I'm all ready to start learning C. I have a book. I downloaded Dev-C++. It's installed, and I type the source code just as I see it:

#include



int main(void)

{

printf("Hello, World!\n");

return 0;

}



I run it through the compiler and run the program. Nothing. A little window--looks like a DOS prompt--pops up and disappears before I can see if anything is written there.



What am I doing wrong? Could it be a setting on the compiler? Could it not be linking the way it should?
anonymous
2009-05-07 11:36:40 UTC
try this:



#include



int main(void)

{

printf("Hello, World!\n");

getchar();

return 0;

}



That should cause it to execute and then pause.



Your problem is, this is a command line app, and it is showing up in that little blip of a screen, you should be running it from the command line as well. no idea how to do this in windows, linux user sorry.
J.M.F.
2009-05-07 11:36:16 UTC
You should run the executable from an already open cmd window, that way it'll stay open. I'm sure it's working - it's just closing before you can see what it's printed.
anonymous
2014-06-19 03:13:35 UTC
confusing matter check out onto google just that can assist


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...