473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Pausing screen on LINUX while using C++

how do we pause screen on LINUX, till user presses any key..
like we use getch() in WINDOWS & getchar() in UNIX..
Dec 29 '06 #1
5 2632
horace1
1,510 Expert 1GB
how do we pause screen on LINUX, till user presses any key..
like we use getch() in WINDOWS & getchar() in UNIX..
try getchar(); it should wait until you hit the ENTER key
Dec 29 '06 #2
i had tried getchar() before posting my problem here.. the program seems not be reacting to this command.. getchar's presence & absence is similar..
Dec 31 '06 #3
horace1
1,510 Expert 1GB
i had tried getchar() before posting my problem here.. the program seems not be reacting to this command.. getchar's presence & absence is similar..
are you reading information from the keyboard (e.g. using scanf()) before attempting to pause. If so the last <enter> key character could be left in the input stream and when you call getchar(); to pause its reads the <enter> and the program carries on. If so you need a second getchar(), e.g.
Expand|Select|Wrap|Line Numbers
  1.     scanf("%d", &i);  // read some data
  2.     getchar();   // read the last <enter> key
  3.     getchar();   // pause for user to hit <enter>
  4.  
the above code works OK under Suse linux 10.1
Dec 31 '06 #4
are you reading information from the keyboard (e.g. using scanf()) before attempting to pause. If so the last <enter> key character could be left in the input stream and when you call getchar(); to pause its reads the <enter> and the program carries on. If so you need a second getchar(), e.g.
Expand|Select|Wrap|Line Numbers
  1.     scanf("%d", &i);  // read some data
  2.     getchar();   // read the last <enter> key
  3.     getchar();   // pause for user to hit <enter>
  4.  
the above code works OK under Suse linux 10.1
with fflush(stdin) & two getchar()'s it has started working.. thanks a ton horace..
Jan 5 '07 #5
Banfa
9,065 Expert Mod 8TB
with fflush(stdin) & two getchar()'s it has started working.. thanks a ton horace..
You shouldn't fflush stdin, it is undefined behaviour and thus very bad.

It is in fact undefined behaviour to fflush any input stream or update (read/write) stream whose most recent operation is a read.

Here is the appropriate section of the C standard
int fflush(FILE *ostream);

ostream points to an output stream or an update stream in which the
most recent operation was not input, the fflush function causes any
unwritten data for that stream to be delivered to the host environment to
be written to the file; otherwise, the behavior is undefined.
Jan 5 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Dave | last post by:
Hi, I have done some research, trying to Clear The Screen in java code. The first option was the obv: system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n"); then i heard about this method:...
12
by: Simon John | last post by:
I'm writing a PyQt network client for XMMS, using the InetCtrl plugin, that on connection receives a track length. To save on bandwidth, I don't want to be continually querying the server for...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
4
by: Paolo Pantaleo | last post by:
Hi, I need to capture a screen snapshot in Linux. PIL has a module IageGrab, but in the free version it only works under Windows. Is there any package to capture the screen on Linux? Thnx...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.