Linux: getch() skips my input

S

Sankar

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
 
C

Chris Dollin

Sankar said:
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.
 
M

Mark McIntyre

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.
 
L

Lew Pitcher

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.development.apps or one of the other linux or unix
newsgroups, where it will be on-topic.

Sorry
 
D

Dik T. Winter

> On 12 Feb 2007 03:50:00 -0800, in comp.lang.c , "Sankar"

>
> Note that getch() isn't standard C, and its behaviour is offtopic
> here.
>
>
> 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.
 
J

Jack Klein

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top