×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How do you exit a program?

How do you exit a program?

How do you exit a program?

(OP)
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


while (<>) {
exit;
}



Where the while() 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

vic cherubini
malice365@hotmail.com
epic software
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
Wants to Know: Java, Cold Fusion, Tcl/TK
====

RE: How do you exit a program?

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.

RE: How do you exit a program?

On some Systems the end of line is linefeed (10). Carriage Return is 13

hnd
hasso55@yahoo.com

RE: How do you exit a program?

(OP)
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

vic cherubini
malice365@hotmail.com
epic software
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
Wants to Know: Java, Cold Fusion, Tcl/TK
====

RE: How do you exit a program?

Hi Vic,

try
return 1;

and main is
int main(){
//stuff

return 1;
}

or
exit(1);

and on a pc ascii 13 is the "Enter" key

the "reset switch" is also a known fav when you get into pointers

HTH
Robert

you'll need to include the <stdlib.h> for exit

RE: How do you exit a program?

If you're using void main(){ then write just return;

RE: How do you exit a program?

alright, try this:

goto OnKeyPress on the form;

in there, put:

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

Cyprus

RE: How do you exit a program?

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.

RE: How do you exit a program?

ok, i used bcb 5, and it worked just fine 4 me, but not 2 many peeps use builder, do they?

Cyprus

RE: How do you exit a program?

Thanx cyprus,
   for your info.

Regards,
SwapSawe.

RE: How do you exit a program?

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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close