Thread: RE: [Dev-C++] How to not close output win?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Reid T. <Rei...@at...> - 2003-10-03 11:46:05
|
Create an exit function that has the system pause in it. Then,
everywhere you wish to exit, call the exit function. Only have to have
it in one place.
=20
=20
reid=20
-----Original Message-----
From: Natalie Bryant [mailto:nap...@lo...]=20
Sent: Friday, October 03, 2003 7:03 AM
To: ber...@ce...
Cc: devc++
Subject: Re: [Dev-C++] How to not close output win?
=09
=09
Thankyou Massimo,
=20
I'll bear that in mind for later when I need it.
=20
Kind regards
=20
Natalie
----- Original Message -----=20
From: Massimo Bertozzi <mailto:kb...@ce...> =20
To: Natalie Bryant
<mailto:nap...@lo...> =20
Cc: devc++ <mailto:dev...@li...>
Sent: Friday, October 03, 2003 11:55 AM
Subject: Re: [Dev-C++] How to not close output win?
On Fri, Oct 03, 2003 at 11:39:33AM +0100, Natalie Bryant
<nap...@lo...> wrote:
=09
> Hi Neszt,
>=20
> Reid sent me this solution yesterday to the same
problem. It instantly made everything work properly... Shown below.
=09
Yes, until you have a single exit in your program.
When you have more
possibilities you have to replicate the system("pause")
everywhere.
=09
M.
--=20
Massimo Bertozzi =20
Dipartimento di Ingegneria dell'Informazione Voice:
+39 0521 90 5735
Parco Area delle Scienze, 181A, Parma, ITALY Fax:
+39 0521 90 5723
WWW: http://www.ce.unipr.it/people/bertozzi E-mail:
ber...@CE...
=20
=09
|
|
From: Reid T. <Rei...@at...> - 2003-10-03 12:09:48
|
EX.=20
=20
#include <stdio.h>=20
#include <stdlib.h>=20
=20
static void myExit(void);=20
static void myFirstExitLocation(int myExitFlag);=20
static void mySecondExitLocation(int myExitFlag);=20
int main(void)=20
{=20
int myExitFlag;=20
myExitFlag =3D 0; /* set to 0 to exit from myFirstExitLocation */=20
/* set to 1 to exit from mySecondExitLocation */=20
/* set to anything else to exit from main */=20
myFirstExitLocation(myExitFlag);=20
mySecondExitLocation(myExitFlag);=20
=20
=20
printf("Exiting from main\n");=20
myExit();=20
return(0); /* never reachable */=20
}=20
=20
void myExit(void)=20
{=20
system("PAUSE");=20
exit(0);=20
}=20
void myFirstExitLocation(int myExitFlag)=20
{=20
printf("In myFirstExitLocation\n");=20
if (myExitFlag =3D=3D 0)=20
{=20
printf("Exiting In myFirstExitLocation\n");=20
myExit();=20
}=20
}=20
void mySecondtExitLocation(int myExitFlag)=20
{=20
printf("In mySecondExitLocation\n");=20
if (myExitFlag =3D=3D 1)=20
{=20
printf("Exiting In mySecondExitLocation\n");=20
myExit();=20
}=20
}=20
=20
=20
reid=20
-----Original Message-----=20
From: Reid Thompson=20
Sent: Friday, October 03, 2003 7:45 AM=20
To: Natalie Bryant; ber...@ce...=20
Cc: devc++=20
Subject: RE: [Dev-C++] How to not close output win?=20
Create an exit function that has the system pause in it. Then,
everywhere you wish to exit, call the exit function. Only have to have
it in one place.
=20
reid=20
-----Original Message-----=20
From: Natalie Bryant [mailto:nap...@lo...]=20
Sent: Friday, October 03, 2003 7:03 AM=20
To: ber...@ce...=20
Cc: devc++=20
Subject: Re: [Dev-C++] How to not close output win?=20
Thankyou Massimo,=20
=20
I'll bear that in mind for later when I need it.=20
=20
Kind regards=20
=20
Natalie=20
----- Original Message -----=20
From: HYPERLINK "mailto:kb...@ce..."Massimo Bertozzi=20
To: HYPERLINK "mailto:nap...@lo..."Natalie Bryant=20
Cc: HYPERLINK "mailto:dev...@li..."devc++=20
Sent: Friday, October 03, 2003 11:55 AM=20
Subject: Re: [Dev-C++] How to not close output win?=20
On Fri, Oct 03, 2003 at 11:39:33AM +0100, Natalie Bryant <HYPERLINK
"mailto:nap...@lo..."nap...@lo...>
wrote:
> Hi Neszt,=20
>=20
> Reid sent me this solution yesterday to the same problem. It instantly
made everything work properly... Shown below.=20
Yes, until you have a single exit in your program. When you have more
possibilities you have to replicate the system("pause") everywhere.=20
M.=20
--=20
Massimo Bertozzi =20
Dipartimento di Ingegneria dell'Informazione Voice: +39 0521 90
5735=20
Parco Area delle Scienze, 181A, Parma, ITALY Fax: +39 0521 90
5723=20
WWW: http://www.ce.unipr.it/people/bertozzi E-mail: HYPERLINK
"mailto:ber...@CE..."ber...@CE...=20
=20
|
|
From: Rossi G. <Gio...@el...> - 2003-10-03 12:46:46
|
You can use "atexit" :
atexit()
Prototype: int atexit(void (_USERENTRY * func)(void));
Header File: stdlib.h
ANSI: C and C++
Explanation: Use atexit to have a function called when the program exits.
The parameter it accepts is a function name, without the typical () of a
function call. It must return void and accept no values (hence the use of
void in the prototype of atexit). If atexit is called more than once, the
last function passed to it will be the first one executed. It can be used up
to 32 times.
Example:
#include <iostream.h>
#include <stdlib.h>
//Program calls atexit with FinalFunction
//FinalFunction is executed before program ends
void FinalFunction(void)
{
cout<<"Final function called - Press enter to exit";
cin.get(); // or system("pause")
}
int main()
{
atexit(FinalFunction);
return 0;
}
Best Regards
Gianni
> -----Original Message-----
> From: Reid Thompson [SMTP:Rei...@at...]
> Sent: Friday, October 03, 2003 1:45 PM
> To: Natalie Bryant; ber...@ce...
> Cc: devc++
> Subject: RE: [Dev-C++] How to not close output win?
>
> Create an exit function that has the system pause in it. Then, everywhere
> you wish to exit, call the exit function. Only have to have it in one
> place.
>
>
>
> reid
>
> -----Original Message-----
> From: Natalie Bryant [mailto:nap...@lo...]
> Sent: Friday, October 03, 2003 7:03 AM
> To: ber...@ce...
> Cc: devc++
> Subject: Re: [Dev-C++] How to not close output win?
>
>
> Thankyou Massimo,
>
> I'll bear that in mind for later when I need it.
>
> Kind regards
>
> Natalie
>
> ----- Original Message -----
> From: Massimo Bertozzi <mailto:kb...@ce...>
> To: Natalie Bryant <mailto:nap...@lo...>
> Cc: devc++ <mailto:dev...@li...>
> Sent: Friday, October 03, 2003 11:55 AM
> Subject: Re: [Dev-C++] How to not close output win?
>
> On Fri, Oct 03, 2003 at 11:39:33AM +0100, Natalie Bryant <
> nap...@lo... <mailto:nap...@lo...>>
> wrote:
>
> > Hi Neszt,
> >
> > Reid sent me this solution yesterday to the same problem.
> It instantly made everything work properly... Shown below.
>
> Yes, until you have a single exit in your program. When
> you have more
> possibilities you have to replicate the system("pause")
> everywhere.
>
> M.
> --
> Massimo Bertozzi
> Dipartimento di Ingegneria dell'Informazione Voice:
> +39 0521 90 5735
> Parco Area delle Scienze, 181A, Parma, ITALY Fax:
> +39 0521 90 5723
> WWW: <http://www.ce.unipr.it/people/bertozzi> E-mail:
> ber...@CE... <mailto:ber...@CE...>
>
>
>
|
|
From: P.D. v. Z. <pa...@my...> - 2003-10-03 13:42:56
|
How about the simplest solution of them all. Simply open a command prompt
yourself, go to your project directory, and execute your console program
from the command line. All those code workarounds are evil. Your "output
window" (console) closes because Dev-C++ simply launches the executable it
just compiled. Windows is responsible for the rest. In Windows, when a
console program has finished executing, its console is closed as well. This
is normal, standard behaviour, and has nothing to do with Dev-C++ (and
Dev-C++ isn't responsible for fixing this either). The solution to this
'problem' is to simply open a command prompt yourself (which you have to
close by yourself as well, will not be automatically closed), and execute
your program in there. Or has the Windows age alienated everyone from
anything having to do with command prompts?
Regards,
Paul
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Rossi
Giovanni
Sent: Friday, October 03, 2003 2:45 PM
To: 'Reid Thompson'; Natalie Bryant; ber...@ce...
Cc: devc++
Subject: RE: [Dev-C++] How to not close output win?
You can use "atexit" :
atexit()
Prototype: int atexit(void (_USERENTRY * func)(void)); Header File: stdlib.h
ANSI: C and C++
Explanation: Use atexit to have a function called when the program exits.
The parameter it accepts is a function name, without the typical () of a
function call. It must return void and accept no values (hence the use of
void in the prototype of atexit). If atexit is called more than once, the
last function passed to it will be the first one executed. It can be used up
to 32 times.
Example:
#include <iostream.h>
#include <stdlib.h>
//Program calls atexit with FinalFunction //FinalFunction is executed before
program ends void FinalFunction(void) {
cout<<"Final function called - Press enter to exit";
cin.get(); // or system("pause")
}
int main()
{
atexit(FinalFunction);
return 0;
}
Best Regards
Gianni
> -----Original Message-----
> From: Reid Thompson [SMTP:Rei...@at...]
> Sent: Friday, October 03, 2003 1:45 PM
> To: Natalie Bryant; ber...@ce...
> Cc: devc++
> Subject: RE: [Dev-C++] How to not close output win?
>
> Create an exit function that has the system pause in it. Then,
> everywhere you wish to exit, call the exit function. Only have to
> have it in one place.
>
>
>
> reid
>
> -----Original Message-----
> From: Natalie Bryant [mailto:nap...@lo...]
> Sent: Friday, October 03, 2003 7:03 AM
> To: ber...@ce...
> Cc: devc++
> Subject: Re: [Dev-C++] How to not close output win?
>
>
> Thankyou Massimo,
>
> I'll bear that in mind for later when I need it.
>
> Kind regards
>
> Natalie
>
> ----- Original Message -----
> From: Massimo Bertozzi <mailto:kb...@ce...>
> To: Natalie Bryant <mailto:nap...@lo...>
> Cc: devc++ <mailto:dev...@li...>
> Sent: Friday, October 03, 2003 11:55 AM
> Subject: Re: [Dev-C++] How to not close output win?
>
> On Fri, Oct 03, 2003 at 11:39:33AM +0100, Natalie Bryant <
> nap...@lo... <mailto:nap...@lo...>>
> wrote:
>
> > Hi Neszt,
> >
> > Reid sent me this solution yesterday to the same problem.
> It instantly made everything work properly... Shown below.
>
> Yes, until you have a single exit in your program. When
you have
> more
> possibilities you have to replicate the system("pause")
everywhere.
>
> M.
> --
> Massimo Bertozzi
> Dipartimento di Ingegneria dell'Informazione Voice:
> +39 0521 90 5735
> Parco Area delle Scienze, 181A, Parma, ITALY Fax:
> +39 0521 90 5723
> WWW: <http://www.ce.unipr.it/people/bertozzi> E-mail:
> ber...@CE... <mailto:ber...@CE...>
>
>
>
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Massimo B. <ber...@ce...> - 2003-10-03 14:05:45
|
On Fri, Oct 03, 2003 at 03:43:28PM +0200, "P.D. van Zelst" <pa...@my...> wrote: > How about the simplest solution of them all. Simply open a command prompt > yourself, go to your project directory, and execute your console program > from the command line. All those code workarounds are evil. Your "output Yes, probably I will be forced to do so if I do not want to change 100 code examples :) > window" (console) closes because Dev-C++ simply launches the executable it > just compiled. Windows is responsible for the rest. In Windows, when a > console program has finished executing, its console is closed as well. This > is normal, standard behaviour, and has nothing to do with Dev-C++ (and > Dev-C++ isn't responsible for fixing this either). The solution to this I do not agree with this. Of course, it is the standard behaviour but I do not find it very confortable. In particular, from a developer point of view, I would like to see my output. At the same time I am much more used to press compile&run, than compile - switch window - execute. Moreover, other compilers behave in a different manner (anyway for all other aspects I like dev c++ a bit more). M. -- Massimo Bertozzi Dipartimento di Ingegneria dell'Informazione Voice: +39 0521 90 5735 Parco Area delle Scienze, 181A, Parma, ITALY Fax: +39 0521 90 5723 WWW: http://www.ce.unipr.it/people/bertozzi E-mail: ber...@CE... |
|
From: Michael D. S. <for...@hi...> - 2003-10-03 14:30:06
|
> Windows is responsible for the rest. In Windows, when a > console program has finished executing, its console is closed as well. Well, yes but there is a /K option to the DOS statement "command" that should keep the window open. I've just been, unsuccessfully, trying to figure a way to get it to recognize that option. Most anything can be done if you want it bad enough. Does that mean it's easy -- that it's worth doing -- that we'll ever figure it out :) ms At 09:05 AM 10/3/03, you wrote: >On Fri, Oct 03, 2003 at 03:43:28PM +0200, "P.D. van Zelst" ><pa...@my...> wrote: > > > How about the simplest solution of them all. Simply open a command prompt > > yourself, go to your project directory, and execute your console program > > from the command line. All those code workarounds are evil. Your "output > >Yes, probably I will be forced to do so if I do not want to change 100 >code examples :) > > > window" (console) closes because Dev-C++ simply launches the executable it > > just compiled. Windows is responsible for the rest. In Windows, when a > > console program has finished executing, its console is closed as well. This > > is normal, standard behaviour, and has nothing to do with Dev-C++ (and > > Dev-C++ isn't responsible for fixing this either). The solution to this > >I do not agree with this. Of course, it is the standard behaviour but I >do not find it very confortable. In particular, from a developer point >of view, I would like to see my output. At the same time I am much more >used to press compile&run, than compile - switch window - execute. > >Moreover, other compilers behave in a different manner (anyway for all >other aspects I like dev c++ a bit more). > >M. >-- >Massimo Bertozzi >Dipartimento di Ingegneria dell'Informazione Voice: +39 0521 90 5735 >Parco Area delle Scienze, 181A, Parma, ITALY Fax: +39 0521 90 5723 >WWW: http://www.ce.unipr.it/people/bertozzi E-mail: ber...@CE... > > >------------------------------------------------------- >This sf.net email is sponsored by:ThinkGeek >Welcome to geek heaven. >http://thinkgeek.com/sf >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
|
From: Daniel G. <sp...@ho...> - 2003-10-03 17:02:25
|
what a great idea!!!
>From: "Reid Thompson" <Rei...@at...>
>To: "Natalie Bryant" <nap...@lo...>,<ber...@ce...>
>CC: "devc++" <dev...@li...>
>Subject: RE: [Dev-C++] How to not close output win?
>Date: Fri, 3 Oct 2003 07:45:16 -0400
>
>Create an exit function that has the system pause in it. Then,
>everywhere you wish to exit, call the exit function. Only have to have
>it in one place.
>
>
>
>reid
>
> -----Original Message-----
> From: Natalie Bryant [mailto:nap...@lo...]
> Sent: Friday, October 03, 2003 7:03 AM
> To: ber...@ce...
> Cc: devc++
> Subject: Re: [Dev-C++] How to not close output win?
>
>
> Thankyou Massimo,
>
> I'll bear that in mind for later when I need it.
>
> Kind regards
>
> Natalie
>
> ----- Original Message -----
> From: Massimo Bertozzi <mailto:kb...@ce...>
> To: Natalie Bryant
><mailto:nap...@lo...>
> Cc: devc++ <mailto:dev...@li...>
>
> Sent: Friday, October 03, 2003 11:55 AM
> Subject: Re: [Dev-C++] How to not close output win?
>
> On Fri, Oct 03, 2003 at 11:39:33AM +0100, Natalie Bryant
><nap...@lo...> wrote:
>
> > Hi Neszt,
> >
> > Reid sent me this solution yesterday to the same
>problem. It instantly made everything work properly... Shown below.
>
> Yes, until you have a single exit in your program.
>When you have more
> possibilities you have to replicate the system("pause")
>everywhere.
>
> M.
> --
> Massimo Bertozzi
> Dipartimento di Ingegneria dell'Informazione Voice:
>+39 0521 90 5735
> Parco Area delle Scienze, 181A, Parma, ITALY Fax:
>+39 0521 90 5723
> WWW: http://www.ce.unipr.it/people/bertozzi E-mail:
>ber...@CE...
>
>
>
_________________________________________________________________
On the move? Get Hotmail on your mobile phone http://www.msn.co.uk/msnmobile
|
|
From: Wing H. Y. <yok...@ve...> - 2003-10-04 02:48:49
|
> >From: "Reid Thompson" <Rei...@at...>
> >Create an exit function that has the system pause in it. Then,
> >everywhere you wish to exit, call the exit function. Only have to have
> >it in one place.
Perhaps instead of an exit function this might be simpler
int main()
{
functionToDoStuff();
system("pause");
return 0;
}
|
|
From: Wing H. Y. <yok...@ve...> - 2003-10-04 08:14:50
|
Nathan Stanley wrote:
>
> From: "Wing H. Yi" <yok...@ve...>
> To: "Daniel Glenfield" <sp...@ho...>
> > int main()
> > {
> > functionToDoStuff();
> >
> > system("pause");
> > return 0;
> > }
>
> In cases where 'functionToDoStuff()' can exit the program, this is not
> acceptable, and is the case in the original email to list. This fix is good
> if your program can only exit at the end of main.
I suggested that alternative so that instead of explicitly exiting,
one could return from whereever in functionToDoStuff for the pause.
Though if there are many different functions that can exit, the use
of an exit function for the pause would be better.
However the 'atexit' suggested in another message sounds like
a cleaner solution.
|
|
From: w.y. <yok...@ve...> - 2003-10-04 20:51:19
|
I thought of another solution to the pause with multiple exits
problem using C++:
class PauseAtEnd
{ public:
~PauseAtEnd() { system("pause"); }
} myPause;
You can put it outside of a function or at the start of main().
|
|
From: Matthews <dem...@uw...> - 2003-10-04 17:15:00
|
Alternately, you can use getchar(), a portable, standard, etc. method of
leaving the input around until you press a key.
At 05:59 PM 03/10/2003 +0100, Daniel Glenfield wrote:
>what a great idea!!!
>
>
>>From: "Reid Thompson" <Rei...@at...>
>>To: "Natalie Bryant" <nap...@lo...>,<ber...@ce...>
>>CC: "devc++" <dev...@li...>
>>Subject: RE: [Dev-C++] How to not close output win?
>>Date: Fri, 3 Oct 2003 07:45:16 -0400
>>
>>Create an exit function that has the system pause in it. Then,
>>everywhere you wish to exit, call the exit function. Only have to have
>>it in one place.
>>
>>
>>
>>reid
>>
>> -----Original Message-----
>> From: Natalie Bryant [mailto:nap...@lo...]
>> Sent: Friday, October 03, 2003 7:03 AM
>> To: ber...@ce...
>> Cc: devc++
>> Subject: Re: [Dev-C++] How to not close output win?
>>
>>
>> Thankyou Massimo,
>>
>> I'll bear that in mind for later when I need it.
>>
>> Kind regards
>>
>> Natalie
>>
>> ----- Original Message -----
>> From: Massimo Bertozzi <mailto:kb...@ce...>
>> To: Natalie Bryant
>><mailto:nap...@lo...>
>> Cc: devc++ <mailto:dev...@li...>
>>
>> Sent: Friday, October 03, 2003 11:55 AM
>> Subject: Re: [Dev-C++] How to not close output win?
>>
>> On Fri, Oct 03, 2003 at 11:39:33AM +0100, Natalie Bryant
>><nap...@lo...> wrote:
>>
>> > Hi Neszt,
>> >
>> > Reid sent me this solution yesterday to the same
>>problem. It instantly made everything work properly... Shown below.
>>
>> Yes, until you have a single exit in your program.
>>When you have more
>> possibilities you have to replicate the system("pause")
>>everywhere.
>>
>> M.
>> --
>> Massimo Bertozzi
>> Dipartimento di Ingegneria dell'Informazione Voice:
>>+39 0521 90 5735
>> Parco Area delle Scienze, 181A, Parma, ITALY Fax:
>>+39 0521 90 5723
>> WWW: http://www.ce.unipr.it/people/bertozzi E-mail:
>>ber...@CE...
>>
>>
>>
>
>_________________________________________________________________
>On the move? Get Hotmail on your mobile phone http://www.msn.co.uk/msnmobile
>
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
>https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|