View Single Post
Old Jun 6th, 2006, 7:45 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
When a console window is finished, it closes. If you don't want it to close, ask it to do something else first. If you don't want it to close until it gets some user input, get some user input:
printf("Press the return key to close the window.\n");
getchar();
return 0;

The getchar function gets a character from the user. Usually, we'd use it as follows:
char myCharacter;
myCharacter = getchar();
But we don't want to use the character for anything - it's just a hack to get the computer to wait around. So instead of storing it in a variable, we just leave it floating around in the ether.

If your code is definitely going to be used only in Windows, you can use the getch function instead of getchar. Whereas getchar waits till the return key is pressed before returning a character, getch will return on the first keypress. You can find it in conio.h.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote