0

I used Code Blocks to generate an exe file from c program. When I open the exe file it opens normally and shows some text that I included in program. But if I give values to program and hit enter it will close automatically. It works fine if I run the program I Code Blocks.

Tell me is there any way building executable that runs fine in window or not? Your kind reply will be very helpful. Thank you.

Vishwasa Navada K
  • 572
  • 1
  • 8
  • 30

2 Answers2

0

It's probably working just fine. Once it receives the input it runs through the rest of your code and then exits. You need to put a pause statement in on the end - something like

system("Pause");

or

cin.get();
AdamHovorka
  • 153
  • 1
  • 7
0

You need to pause the system after execution of programm.

Either use:

system("pause");

or

cin.get();
cin.ignore();

I will recommend you using the second method because its plateform dependent.

It's frowned upon because it's a platform-specific hack that has nothing to do with actually learning programming, but instead to get around a feature of the IDE/OS - the console window launched from Visual Studio closes when the program has finished execution, and so the new user doesn't get to see the output of his new program.

See this answer!

Community
  • 1
  • 1
ashu
  • 1,756
  • 4
  • 22
  • 41