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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you exit a program? 1

Status
Not open for further replies.

vcherubini

Programmer
May 29, 2000
527
0
0
US
Hello:

I am brand new to C++, and am a native Perl programmer.

What I was wondering, is how would you exit a program after someone has pressed the Enter key.

I know in Perl it is

[tt]
while (<>) {
exit;
}

[/tt]

Where the [tt]while()[/tt] statement waits for the user to press Enter, and when that condition is true, it exits the program.

How would do you this in C++?

All help is appreciated greatly.

Thank you.

-Vic [sig]<p>vic cherubini<br><a href=mailto:malice365@hotmail.com>malice365@hotmail.com</a><br><a href= software</a><br>====<br>
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director<br>
Wants to Know: Java, Cold Fusion, Tcl/TK<br>
====[/sig]
 
Well you'd have to read the enter key first and then use in the while condition. In dos based program you'd read it with getch and save it in variable. But you will have to find out what is the code for enter (I think it's 13 but I'm not sure). You can put the if sentence in the while brackets. [sig][/sig]
 
On some Systems the end of line is linefeed (10). Carriage Return is 13 [sig]<p>hnd<br><a href=mailto:hasso55@yahoo.com>hasso55@yahoo.com</a><br><a href= > </a><br> [/sig]
 
First, thanks for responding all of you that did.

I get what you are saying with the while command, but what is the command in order to make the window close.

I know that you can use getch(); to make the window inactive, but is there a way to make it actually close it self?

Hope this helps to clear up any confusion.

Thanks a lot.

-Vic [sig]<p>vic cherubini<br><a href=mailto:malice365@hotmail.com>malice365@hotmail.com</a><br><a href= software</a><br>====<br>
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director<br>
Wants to Know: Java, Cold Fusion, Tcl/TK<br>
====[/sig]
 
Hi Vic,

try
return 1;

and main is
int main(){
//stuff

return 1;
}

or
exit(1);

and on a pc ascii 13 is the &quot;Enter&quot; key

the &quot;reset switch&quot; is also a known fav when you get into pointers ;-)

HTH
Robert

you'll need to include the <stdlib.h> for exit [sig][/sig]
 
If you're using void main(){ then write just return; [sig][/sig]
 
alright, try this:

goto OnKeyPress on the form;

in there, put:

if (Key==VK_RETURN)
{
Application->Terminate();
} Cyprus
 
Cyprus,

I would like know which compiler u r using in C++ to do this and which header file contains the Application structure pointer calling a Terminate function. Probably this could be a learning experience to me.

Regards,
SwapSawe.

vcherubini,


you can use both exit(1) and return(this has to be in main) as Robert has suggested but for exit(1) u'll be required to include stdlib.h

Regards,
SwapSawe.
 
ok, i used bcb 5, and it worked just fine 4 me, but not 2 many peeps use builder, do they?
Cyprus
 
If your using Builder closing a program is ridiculously easy.
Simply click on the mainform and inthe object inspector
under Events choose the OnClose Event by DoubleClicking on it. Now that the code window is up you'll see it is at a function like Void _fastcall MainForm_OnClose(...)
Just type in that function one little word:

Void _fastcall MainForm_OnClose(...)
{
Close();
}

Next question please?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top