C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 14th, 2005, 10:16 AM
Sun Sun is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 24 Sun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 19 sec
Reputation Power: 0
Unhappy How to pause in C

Hi everyone,

I am a beginner of C, and C++. Now, I have a question, when I write C++, I will write a cin.get () ; to pause the window.

But, what should I write in C to have the same function??

Because I run the C programme, the window close too fast before I can see anything.

Thank you very much for your help.

Regards,
Sun.

Reply With Quote
  #2  
Old July 14th, 2005, 10:40 AM
Diocletian Diocletian is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 2 Diocletian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 49 sec
Reputation Power: 0
I always just add a separate variable, and for a cin at the end of the program. I think I only run into the window-dropping problem with VS 6.0, seems to hang on the screen untill closed with .net. I'm sure there's a pause function of some sort out there, but I've always felt it was easier to do it this way:

int main()
{
Int m;


--All of your code here--

cin >> m;
}
Kind of sloppy, but it works.

Reply With Quote
  #3  
Old July 14th, 2005, 11:13 AM
Sun Sun is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 24 Sun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 3 m 19 sec
Reputation Power: 0
Thanks a lot!!!

I learn something from you.

Reply With Quote
  #4  
Old July 14th, 2005, 11:13 AM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 9
Send a message via AIM to Geo.Garnett
I agree, There probably is a better way of doing it, but I do the same thing. If you are writing a program were you want your user to see the final result of there last question or something it always helps to have the last operation, the user inputting some type of integer. and just to add to your code Diocletian, you could also do something like this!!
Code:
int main()
{
Int m;


--All of your code here--

cout>>" Enter 1 To exit \n";
cin >> m;
}

Just to make it a little more formal to the user

Reply With Quote
  #5  
Old July 14th, 2005, 02:04 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 24 m 9 sec
Reputation Power: 10
The C equivilent of "cin.get()" is "getchar()", it does the exact same thing.
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips.



Reply With Quote
  #6  
Old February 25th, 2010, 08:47 AM
praveenk63 praveenk63 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Posts: 1 praveenk63 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 58 sec
Reputation Power: 0
pause in c

just type the following code after writing the c program ie at the end before closing the main function

system("PAUSE");
return 0;

that's it will work i guess

Reply With Quote
  #7  
Old February 25th, 2010, 10:54 PM
Nila Nila is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Posts: 2 Nila User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 24 m 31 sec
Reputation Power: 0
Pause a C program

You could use

sleep(n);

where n is the number of seconds you want to pause for.

Reply With Quote
  #8  
Old May 20th, 2011, 12:45 PM
swidmer swidmer is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 1 swidmer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by Sun
Hi everyone,

I am a beginner of C, and C++. Now, I have a question, when I write C++, I will write a cin.get () ; to pause the window.

But, what should I write in C to have the same function??

Because I run the C programme, the window close too fast before I can see anything.

Thank you very much for your help.

Regards,
Sun.


another simple method is to use:

while(!getch());

you will be paused until any key is hit,
delay(xxx); will pause for xxx ticks too.

Reply With Quote
  #9  
Old June 7th, 2011, 10:26 PM
Electodemon Electodemon is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 37 Electodemon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 23 m 53 sec
Reputation Power: 4
system("pause");
return 0;

Seems the most convenient method. And it doesn't require use of a variable.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > How to pause in C


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap