Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,360 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,220 people online right now. Registration is fast and FREE... Join Now!




c program closes as soon as it executes

 
Reply to this topicStart new topic

c program closes as soon as it executes

macaroni
post 23 Aug, 2008 - 03:37 AM
Post #1


New D.I.C Head

*
Joined: 23 Aug, 2008
Posts: 3


My Contributions


I have just downloaded the sybase open watcom compiler on a windows xp machine running an intel processor and purchased "let us C 8th edition" and am now ready to figure out this c language thing. (don't know if all this detail is even needed)
I wrote and compiled "hello world" and when I execute the program it appears on the screen for a nano-second and closes.
If anyone knows how to prevent this program and any other program from closing until I decide to close it that would be greatly appreciated. Please bear in mind that the extent of my knowledge is "hello world"
I look forward to any helpful advice
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 23 Aug, 2008 - 03:47 AM
Post #2


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,402



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


You need to hold the execution window open.

EDIT:
Oops, I gave you some C++ code, not C blush.gif
User is offlineProfile CardPM

Go to the top of the page

darrylng88
post 23 Aug, 2008 - 04:15 AM
Post #3


New D.I.C Head

*
Joined: 23 Aug, 2008
Posts: 1

QUOTE(macaroni @ 23 Aug, 2008 - 04:37 AM) *

I have just downloaded the sybase open watcom compiler on a windows xp machine running an intel processor and purchased "let us C 8th edition" and am now ready to figure out this c language thing. (don't know if all this detail is even needed)
I wrote and compiled "hello world" and when I execute the program it appears on the screen for a nano-second and closes.
If anyone knows how to prevent this program and any other program from closing until I decide to close it that would be greatly appreciated. Please bear in mind that the extent of my knowledge is "hello world"
I look forward to any helpful advice


Put a

system("pause");


before

return 0;

or before

return EXIT_SUCCESS;
User is offlineProfile CardPM

Go to the top of the page

macaroni
post 23 Aug, 2008 - 04:23 AM
Post #4


New D.I.C Head

*
Joined: 23 Aug, 2008
Posts: 3


My Contributions


QUOTE(gabehabe @ 23 Aug, 2008 - 04:47 AM) *

You need to hold the execution window open.

EDIT:
Oops, I gave you some C++ code, not C blush.gif


Thanks for the help. I used the getch(); and that did the trick. with this I hope I can make it passed the homework in the first chapter.

Cheers. biggrin.gif
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 23 Aug, 2008 - 04:26 AM
Post #5


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,402



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


Glad I could help smile.gif

Just to make sure though, you do know that conio is a non-standard header, and won't work on all compilers, don't you?
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 04:34AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month