Pausing program with getchar();

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2006
Posts: 37
Reputation: Firestone is an unknown quantity at this point 
Solved Threads: 0
Firestone Firestone is offline Offline
Light Poster

Pausing program with getchar();

 
0
  #1
Jul 13th, 2007
My compiler won't pause on getchar();. I have Dev C++ 4.9.9.2 and if I put getchar(); at the end of the program, it doesn't stop, and the console window still exits. It still exits when I assign a variable to it
c = getchar();
Is there another way to pause the program with C, without using system("PAUSE");
=================================
There are 10 types of people in the world,
Those who understand binary, and those who don't
=================================
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,412
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1469
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Pausing program with getchar();

 
0
  #2
Jul 13th, 2007
The program will not stop if there are still keystroks in the keyboard buffer, such as if you previously called scanf() to get an integer the '\n' will still be in the keyboard buffer. But you will have to post your program for anyone to give you more help with this.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,679
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Pausing program with getchar();

 
0
  #3
Jul 13th, 2007
>Is there another way to pause the program with C, without using system("PAUSE");
Sure. Don't run your program in an IDE that isn't smart enough to keep the window open. Run it from the command prompt.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Pausing program with getchar();

 
0
  #4
Jul 13th, 2007
The problem arises when you are using different variables to read stuff, like ints and strings.

My advice would be to read everything in as a string and just convert to ints or floats where necessary.
Last edited by iamthwee; Jul 13th, 2007 at 5:30 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,679
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Pausing program with getchar();

 
0
  #5
Jul 13th, 2007
The problem arises when you don't know how C uses stream based input. You can mix input methods without any trouble if you know what happens, but most people just make function calls without knowing what's going on. The ideal fix is to learn how stream I/O works and learn what each input function does.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Pausing program with getchar();

 
0
  #6
Jul 13th, 2007
That too but my way is best, safer (for newbies ) and works
Last edited by iamthwee; Jul 13th, 2007 at 5:23 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 37
Reputation: Firestone is an unknown quantity at this point 
Solved Threads: 0
Firestone Firestone is offline Offline
Light Poster

Re: Pausing program with getchar();

 
0
  #7
Jul 13th, 2007
Its ok, I switched to a new IDE and it solved the problem. Thanks for the help guys.
=================================
There are 10 types of people in the world,
Those who understand binary, and those who don't
=================================
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,679
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 727
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Pausing program with getchar();

 
0
  #8
Jul 13th, 2007
>but my way is best
No, your way promotes ignorance. Mine promotes learning.

>safer (for newbies )
Trading one mystery for another isn't safer.

>and works
Which is why I didn't immediately correct you.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Pausing program with getchar();

 
0
  #9
Jul 13th, 2007
LOL

Which IDE did you change too. BTW I think you should try my idea cos I bet it works.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 37
Reputation: Firestone is an unknown quantity at this point 
Solved Threads: 0
Firestone Firestone is offline Offline
Light Poster

Re: Pausing program with getchar();

 
0
  #10
Jul 13th, 2007
Pelles C. Its a good IDE, similar to Dev C++. I don't know how to convert from type to another anyways...
Last edited by Firestone; Jul 13th, 2007 at 5:57 pm. Reason: Typo
=================================
There are 10 types of people in the world,
Those who understand binary, and those who don't
=================================
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC