Author Topic: Application not running  (Read 5906 times)

kaulimus

  • Guest
Application not running
« on: December 11, 2007, 05:14:25 pm »
Hello, all!

I have a newbie question for you. I'm just learning to program with C++ (or rather, reviewing some of what I already knew to get to the stuff I don't). I've written and built my "Hello World" application no problem. It runs from the compiler just fine. When I double click my application's icon on the desktop, however, nothing happens. Is this normal?

Thanks,
-Jake

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Application not running
« Reply #1 on: December 11, 2007, 05:50:50 pm »
No. If this were normal, you would need Visual Studio to run Microsoft Word.

Probably "nothing happens" is not correct, either. More likely it only happens too fast for you to see.
Try running cmd and starting your Hello World from there.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

kaulimus

  • Guest
Re: Application not running
« Reply #2 on: December 12, 2007, 03:20:31 am »
I'll give it a shot and do some more fiddling around.

And yes, you're accurate in saying that "nothing happens" is not the best way to phrase what is happening. It happens just fast enough for me to catch a glimpse of the application before it terminates.

EDIT: I can get it to run in the command prompt window. Any ideas as to why it won't otherwise?

Thanks,
-Jake
« Last Edit: December 12, 2007, 03:58:14 am by kaulimus »

Offline eckard_klotz

  • Almost regular
  • **
  • Posts: 201
Re: Application not running
« Reply #3 on: December 12, 2007, 05:47:06 am »
Hello Jake.

I think this is the normal behaviour under windows if you don't have an input-command or a command like system("PAUSE") at the end of the application. I guess your application has only an output-command to print the "Hello World" to the screen.  After that the program is finished, right?

And that's what windows is doing. A terminal-window is opened, "hello world" is printed and the terminal-window is closed because there is no need to let it open for nothing. You can solve this problem in several ways.

1. You can write a batch-file to run your application with the command PAUSE at the end without changing your application. This gives the user the chance to decide if the window should close or not after the program is finished. If your application should be combined with other applications it may be useful if there is no need to close the window by hand to step further except for batch-file debugging.

2. You can ad the command system("PAUSE"); after the output-line of your c-source but this is not supported of all operation systems and it is officially not recommended.

3. You can add a loop with a real input-command after the output-line. Run the loop until the user inputs "exit" or something like this.

I hope this will help you,

                                  Eckard.

Offline JGM

  • Lives here!
  • ****
  • Posts: 518
  • Got to practice :)
Re: Application not running
« Reply #4 on: December 12, 2007, 01:26:35 pm »
2. You can ad the command system("PAUSE"); after the output-line of your c-source but this is not supported of all operation systems and it is officially not recommended.

the function getchar() on the stdio.h or cstdio is also a good alternative at the end of the program, really simple one.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Application not running
« Reply #5 on: December 12, 2007, 02:55:27 pm »
Note that the normal behaviour that you would want 99.99% of the time is indeed the one you have.

There are very, very few valid reasons for blocking a program that has finished running. Normally, if the program is done with whatever it was doing, it should exit. The batch file solution is still the best, in my opinion, as it leaves the actual program unmodified.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline alchemist

  • Multiple posting newcomer
  • *
  • Posts: 38
    • My Blog
Re: Application not running
« Reply #6 on: December 12, 2007, 03:23:51 pm »
or use cb_console_runner ?
Kind Regards,
Xavier Miller.
http://xaviermiller.be

kaulimus

  • Guest
Re: Application not running
« Reply #7 on: December 12, 2007, 04:00:20 pm »
Wonderful, thank you! I hadn't considered that the program would end itself considering that it didn't from the command prompt window and when run through the compiler, but I suppose that does make sense.

Thank you for all your help, everyone!
-Jake