944,214 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 5149
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 13th, 2007
0

Pausing program with getchar();

Expand Post »
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");
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Firestone is offline Offline
37 posts
since Nov 2006
Jul 13th, 2007
0

Re: Pausing program with getchar();

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,966 posts
since Aug 2005
Jul 13th, 2007
0

Re: Pausing program with getchar();

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jul 13th, 2007
0

Re: Pausing program with getchar();

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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 13th, 2007
0

Re: Pausing program with getchar();

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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jul 13th, 2007
0

Re: Pausing program with getchar();

That too but my way is best, safer (for newbies ) and works
Last edited by iamthwee; Jul 13th, 2007 at 5:23 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 13th, 2007
0

Re: Pausing program with getchar();

Its ok, I switched to a new IDE and it solved the problem. Thanks for the help guys.
Reputation Points: 10
Solved Threads: 0
Light Poster
Firestone is offline Offline
37 posts
since Nov 2006
Jul 13th, 2007
0

Re: Pausing program with getchar();

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jul 13th, 2007
0

Re: Pausing program with getchar();

LOL

Which IDE did you change too. BTW I think you should try my idea cos I bet it works.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jul 13th, 2007
0

Re: Pausing program with getchar();

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
Reputation Points: 10
Solved Threads: 0
Light Poster
Firestone is offline Offline
37 posts
since Nov 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: wierd strcat behaivour
Next Thread in C Forum Timeline: Connecting SQL plus With C....





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC