473,566 Members | 3,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linux: getch() skips my input

Dear all,
In my programming snippet compiled in Linux 2.6, I have a getch() ,
but the program when executed does not wait for my input..
fflush(stdin), fflush(stdout) - All these did not help.

I would appreciate if somone suggests me proven solution to this.

thanks in advance
Sankar

Feb 12 '07 #1
5 5230
Sankar wrote:
In my programming snippet compiled in Linux 2.6, I have a getch() ,
but the program when executed does not wait for my input..
You've probably got some characters left lying around in the input
stream. Maybe you had a scanf and forgot to consume the newline.

Since I /can't see your code/, I can't really be more helpful than
that.
fflush(stdin), fflush(stdout) - All these did not help.
Well, `fflush(stdin)` has Undefined Behaviour [1]. Hoping that this
UB will happen to solve your problem qualifies as reckless optimism.
I would appreciate if somone suggests me proven solution to this.
The proven solution is to understand what the problem is and then
apply the appropriate remedy.

--
Chris "electric hedgehog" Dollin
"No-one here is exactly what he appears." G'kar, /Babylon 5/

Feb 12 '07 #2
On 12 Feb 2007 03:50:00 -0800, in comp.lang.c , "Sankar"
<wr************ @gmail.comwrote :
>Dear all,
In my programming snippet compiled in Linux 2.6, I have a getch() ,
Note that getch() isn't standard C, and its behaviour is offtopic
here.
>but the program when executed does not wait for my input..
Sounds like a FAQ - 12.18a maybe ? see my sig
>fflush(stdin ),
undefined behaviour.

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
Feb 12 '07 #3
On Feb 12, 6:50 am, "Sankar" <writetoshan... @gmail.comwrote :
Dear all,
In my programming snippet compiled in Linux 2.6, I have a getch() ,
but the program when executed does not wait for my input..
fflush(stdin), fflush(stdout) - All these did not help.
As others have told you, getch() is not a standard C function, and
fflush(stdin) invokes undefined behaviour.

My (off-topic) question to you is "Why do you use getch()? Since you
mention that you are developing in a Linux 2.6 environment, your
mention of getch() implies that you have developed a "curses" based
program, which seems a little too advanced in the light of your
question. Are you certain that you know what getch() does in your
environment? Have you read the documentation that came with the curses
library on what getch() does, and what sort of parameters (and input)
that it expects?"
I would appreciate if somone suggests me proven solution to this.
No suggestions other than to ask your question in
comp.os.linux.d evelopment.apps or one of the other linux or unix
newsgroups, where it will be on-topic.

Sorry
--
Lew

Feb 12 '07 #4
In article <sd************ *************** *****@4ax.comMa rk McIntyre <ma**********@s pamcop.netwrite s:
On 12 Feb 2007 03:50:00 -0800, in comp.lang.c , "Sankar"
<wr************ @gmail.comwrote :
Dear all,
In my programming snippet compiled in Linux 2.6, I have a getch() ,

Note that getch() isn't standard C, and its behaviour is offtopic
here.
but the program when executed does not wait for my input..

Sounds like a FAQ - 12.18a maybe ? see my sig
I think not. If "getch" from curses is used, it will indeed return
immediately, unless used within a curses window.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Feb 12 '07 #5
On Mon, 12 Feb 2007 14:48:05 GMT, "Dik T. Winter" <Di********@cwi .nl>
wrote in comp.lang.c:
In article <sd************ *************** *****@4ax.comMa rk McIntyre <ma**********@s pamcop.netwrite s:
On 12 Feb 2007 03:50:00 -0800, in comp.lang.c , "Sankar"
<wr************ @gmail.comwrote :
>
Dear all,
In my programming snippet compiled in Linux 2.6, I have a getch() ,
>
Note that getch() isn't standard C, and its behaviour is offtopic
here.
>
but the program when executed does not wait for my input..
>
Sounds like a FAQ - 12.18a maybe ? see my sig

I think not. If "getch" from curses is used, it will indeed return
immediately, unless used within a curses window.
There is no "getch" or "curses" in standard C. Like all non-standard
extensions, it is off-topic here.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Feb 13 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2386
by: Scott Navarre | last post by:
Hi, I have Red Hat 8.0 and have the default Mozilla browser that comes with it. I am programming in javascript and have come across something problematic. Given the following code: <HTML> <HEAD> </HEAD> <BODY> <FORM>
3
5360
by: voidstar | last post by:
Hi, I have the following problem: I use "getch" to monitor keypresses and the I use "cin" to input a string. When I type in 'y', the 'y' character appears, so I need to hit backspace before typing the string. c = getch(); cin >> str;
2
2598
by: Shugong Wang | last post by:
getch() function is not a standard C/C++ function. Thought gcc provieds ncurses.h and a getch() function is realized, I still want to know how to realize a getch() function in standard c or c++.
15
3732
by: Profetas | last post by:
Hi, How do I read a char from stdin before the '\n' is pressed? for example I know that I can use getch() to read a single char from the user input, but suppose I wanted to read before the carriage return is pressed. for example I type a char and the following actions is done before the '\n' is pressed.
2
2066
by: Patrick M. | last post by:
Hello everyone. I'm creating a simple bingo game. After the board is drawn on the screen, I try to get input from the user. If they enter an 'm', the application marks the random letter and number on the bingo board. If they type 'b', the application checks for bingo... you get the point. Now, if no input is received within x seconds, I...
4
11612
by: Crow | last post by:
Is there any way to make cin behave like getch()? Specifically, getch() returns immediately after a key is pressed and the cin family of input methods seem to block until a new line is encountered. I need some help.
9
3041
by: James McLaughlin | last post by:
Hi, Does anyone know if it's possible to write either a getch() (preferably Borland-style) or getche() function in C without it being platform-dependent or otherwise non-standard? If not, can someone suggest a good alternative for situations where you require the user to "press any key to continue" or "press Enter to continue" - with...
3
40248
by: GLCODER | last post by:
Does anyone know of a getch() equivalent that exists in linux? I have just started doing some basic programming and am currently running Knoppix on CD. So I'm not sure what kind of file library I have available. Any help would be greatly appreciated; GL
7
6147
by: Markus Mayer | last post by:
Hi folks. I'm somewhat new to *nix programming and just ran into a problem. I have to take user input from the terminal but like to constrain that to some rules given, i.e. "numbers only" or "alphanumeric only" etc. scanf would do, but I don't like the fact that wrong ('disallowed') characters are visible and all that stuff. For that I need...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6263
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.