Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbi question

Status
Not open for further replies.

taymo2020

Programmer
Mar 6, 2005
2
US
I have a bloodshed dev c/c++ compiler. I have a simple program writeen that displays "Whats the hizzle?"lol. Anyways when i run it all it does is display the command prompt one time really quick. It doesnt stay. I was wondering why this happens and how to solve it.
 
Code:
int main(void) {
             return printf("What's the hizzle?\n');
}
[code]
 
Run your program from the command prompt in the first place.

Alternately, go into your executable's Advanced Preferences and find an option about "Keeping DOS Window Open" or something similar.

Alternately, you could add the line:
Code:
system("pause");
after the main part of your code. That way's non-portable and bad practice, though.

Just use the first method and run it from the command prompt.


As for why it happens, the system opens a window for your program, your program stops, and the system closes the window for your program since it's not running anymore.


The first method keeps the system from giving the program its own window, so it doesn't close when your program stops.

The second method keeps the system from closing the window automatically after your program ends.

The third method keeps your program running until you hit a key, and the system doesn't close the window until your program finishes.
 
You might add the lines

Code:
printf("\nPress enter to continue\n");
getchar();

which does much like

Code:
system("pause");
 
First, open a command prompt. There's probably something in your Applications menu to do that. Alternately, you can select "Run Program" from the Start menu and run "cmd" or "command" or something similar.

Once you have it open, navigate to the directory where your program is located and, assuming you named your program [tt]hizzle.exe[/tt], type:
Code:
./hizzle.exe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top