473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Totally Newb question

10
Anytime I compile and run a program the command prompt pops up and then closes quickly. Is there anyway I can make it so.....it doesn't close on me?
Apr 30 '07 #1
4 1265
gpraghuram
1,275 Expert 1GB
Hi,
Before returnng from the main use the function getchar()
Until u type in something the console wont close.

Thanks
Raghuram
Apr 30 '07 #2
xoinki
110 100+
or u can also use getch() at the end of the program..
getch() waits for a character input from the user. as soon as u press some key it takes as input and terminates the program..
xoinki
Apr 30 '07 #3
Banfa
9,065 Expert Mod 8TB
It is doing it because you are running it via the debugger, the debugger does not pause when the program exits.

If instead of running it via the debugger you execute it (which runs it via the system) then (on Windows certainly) the system will pause the console after the program exits so you can view the output.

Putting getchar() or getc() or whatever at the end of the program is a poor solution because it is not actually desired behaviour of the program. If you run this program from a console window (once you have finished deleloping) then you will unnecessarily have to hit enter to get the program to exit back to the command prompt. If you double click it from an explorer window (I'm assuming Windows OS) then you will have to hit enter twice to get the program to exit, once for the CherChar and once for the pause the system does for you.

The point is this is about how you use your IDE, learn how it works properly don't alter you code to get round your lack of knowledge.
Apr 30 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
If you are using Visual Studio.NET, then the flashing black window was your program executing after you selected "Start".

If you select "Start Without Debugging", Visual Studio will pause after main() completes with:

Press any key to continue...

What happens is that unless you specify, your executable is compiled with code to run the debugger. By selecting "Start", you are telling Visual Studio to just run the code. The implication is that you ahve built-in breaks to stop the program. By selecting "Start Without Deubgging", you are telling Visual Studio that you are not using your debugger. Now Visual Studio will pause at the end of main() so you can see what happened.
Apr 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
0
by: David E. | last post by:
So as a programmer, what's the best thing to study? EJB? How much of the J2EE or Enterprise architecture is necessary to no? I guess I need a good overview for a newb like me... thanks.. --...
54
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
3
by: Walter | last post by:
But I'm stumped..... I've got a windows 2000 server and I am trying to set up PHPBB on it using a mysql database.. I am very inexperienced on this..... Ive installed mysql V4.0.20d and I can...
3
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
6
by: Sean Berry | last post by:
Hello all I have build a list that contains data in the form below -- simplified for question -- myList = ,, ...] I have a function which takes value3 from the lists above and returns...
2
by: python programming newb | last post by:
Hi all, first post. I'm new to python and tkinter. I'm trying to write a program that opens the root window with a button that then opens a toplevel window that then has it's own widgets. I...
2
by: J | last post by:
Greetings Group- I'm trying to put together a pattern matching script that scans a directory tree for tif images contained in similar folder names, but running into a NewB problem already. Is it...
1
by: jgibbens | last post by:
First, thank you for even looking at my question. I am using VB 2005 and I have a question about XML. what I want to do is: 1. keep adding to this file with out over writing it 2. be able...
3
by: DaveJ | last post by:
Hi everyone, I really was hesitant to post here for fear of seeming foolish but I really am desparate, and do appreciate any opportunity to get answers from real people. So please forgive the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.