4

Possible Duplicate:
C/C++: Capture characters from standard input without waiting for enter to be pressed

I'm using C-Free 4 Standard on windows 7 and I writing a C program.

I'm using getch() as a function to pause the program, however, the character(s) pressed echos on the screen and it waits for the Enter key to be pressed before moving on (it doesn't look any different than how the scanf works). I tried getche(), and it works fine, although the echo appears.

What could be the problem with the getch() function?

Community
  • 1
  • 1
Raam Kumar
  • 127
  • 2
  • 11

2 Answers2

2

The getch, wgetch, mvgetch and mvwgetch, routines read a character from the window. In no-delay mode, if no input is waiting, the value ERR is returned. In delay mode, the program waits until the system passes text through to the program. Depending on the setting of cbreak, this is after one character (cbreak mode), or after the first newline (nocbreak mode). In half-delay mode, the program waits until a character is typed or the specified timeout has been reached.

More or less the same method is used in Windows. You can use _getch() to get the input character available for the application without buffering.

codewarrior
  • 1,269
  • 1
  • 9
  • 14
0

In fact there are several ways to pause the execution of your program until you enter something, one way to do that is by using getchar() (which is part of the function set of stdio.h and an official standard library), It will do the same effect as getch() (this function is part of the functions set of conio.h library which isn't an official library).

If your problem is that you want to avoid pressing Enter every time you enter a character which is not very clear in your question), then read this: How to avoid press enter with any getchar()

Community
  • 1
  • 1
Alberto Bonsanto
  • 17,556
  • 10
  • 64
  • 93