Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > getch?

Reply
Thread Tools

getch?

 
 
Profetas
Guest
Posts: n/a
 
      11-02-2004
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.

Thanks

 
Reply With Quote
 
 
 
 
Chris Torek
Guest
Posts: n/a
 
      11-02-2004
In article
<news:(E-Mail Removed) alkaboutprogramming.com>
Profetas <(E-Mail Removed)> wrote:
>How do I read a char from stdin before the '\n' is pressed?


See the comp.lang.c FAQ, question 19.1.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
 
Reply With Quote
 
 
 
 
Michael Mair
Guest
Posts: n/a
 
      11-02-2004


Profetas wrote:
> 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.


FAQ 19.4

Your questions *always* are FAQ slightly rewritten -- either you
are doing this to keep us busy or you are too lazy to read the thing.
Not fair. As promissed:

*PLONK*
--
E-Mail: Mine is a gmx dot de address.

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      11-02-2004
Profetas wrote:
> Hi,
>
> How do I read a char from stdin before the '\n' is pressed?


This is Question 19.1 in the comp.lang.c Frequently
Asked Questions (FAQ) list

http://www.eskimo.com/~scs/C-faq/top.html

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


<OT>Has anyone else noticed that on this newsgroup
the phrase "I know" almost always introduces a false
statement, or at the very least a gross misunderstanding?
I know I can't be the only one who-- oh, drat!</OT>

There is no getch() function in Standard C. If your
C implementation happens to provide one, it's some kind
of extension to C, tacked on rather than inherent.

> for example I type a char and the following actions is done before the
> '\n' is pressed.


FAQ.

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Michael Mair
Guest
Posts: n/a
 
      11-02-2004
> FAQ 19.4
Corr: FAQ 19.1
Sorry
--
E-Mail: Mine is a gmx dot de address.

 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      11-02-2004
Profetas wrote:

> Hi,
>
> How do I read a char from stdin before the '\n' is pressed?


ITYM: "How do I read the FAQ?"

> for example I know that I can use getch()


There is no 'getch' in C. You know something that isn't true.

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

 
Reply With Quote
 
Christopher Benson-Manica
Guest
Posts: n/a
 
      11-02-2004
Eric Sosman <(E-Mail Removed)> spoke thus:

> <OT>Has anyone else noticed that on this newsgroup
> the phrase "I know" almost always introduces a false
> statement, or at the very least a gross misunderstanding?


Which is why I typically forego using it; it lessens the sting when I
turn out to be wrong

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
 
Reply With Quote
 
Profetas
Guest
Posts: n/a
 
      11-03-2004
NAME
getch, wgetch, mvgetch, mvwgetch, ungetch, has_key - get (or
push back)
characters from curses terminal keyboard

SYNOPSIS
#include <curses.h>

int getch(void);
int wgetch(WINDOW *win);
int mvgetch(int y, int x);
int mvwgetch(WINDOW *win, int y, int x);
int ungetch(int ch);
int has_key(int ch);

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


 
Reply With Quote
 
Joona I Palaste
Guest
Posts: n/a
 
      11-03-2004
Profetas <(E-Mail Removed)> scribbled the following:
> NAME
> getch, wgetch, mvgetch, mvwgetch, ungetch, has_key - get (or
> push back)
> characters from curses terminal keyboard


> SYNOPSIS
> #include <curses.h>


Curses is a platform-specific extension to C and not a part of ISO
standard C.

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"How can we possibly use sex to get what we want? Sex IS what we want."
- Dr. Frasier Crane
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      11-03-2004
In <cma6ek$4sl$(E-Mail Removed)> Joona I Palaste <(E-Mail Removed)> writes:

>Curses is a platform-specific extension to C and not a part of ISO
>standard C.


It is not part of ISO standard C, but it is the best you can get in terms
of platform *independent* API for full screen programming. You're
likely to find a curses implementation for every hosted implementation
on which full screen programming makes sense.

OTOH, it is ludicrous to use curses if all you want is the ability to
get direct access to the user input.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
Currently looking for a job in the European Union
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments