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 15 3716
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.
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.
-- Er*********@sun.com
> FAQ 19.4
Corr: FAQ 19.1
Sorry
--
E-Mail: Mine is a gmx dot de address.
In article
<news:43******************************@localhost.t alkaboutprogramming.com>
Profetas <xu*****@yahoo.com> 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 (40°39.22'N, 111°50.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.
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.
Eric Sosman <er*********@sun.com> 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.
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.
Profetas <xu*****@yahoo.com> 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 (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"How can we possibly use sex to get what we want? Sex IS what we want."
- Dr. Frasier Crane
In <cm**********@oravannahka.helsinki.fi> Joona I Palaste <pa*****@cc.helsinki.fi> 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: Da*****@ifh.de
Currently looking for a job in the European Union
"Profetas" <xu*****@yahoo.com> wrote in message news:<e4******************************@localhost.t alkaboutprogramming.com>... 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.
Lovely. However, curses is not a part of the standard C library, and
is not a part of every C implementation out there (I don't think
you're going to find curses in MSVC). curses is an extension,
provided by a specific implementation.
C does not provide high-level (built-in) support for reading
individual keystrokes; this is something that's specific to your
particular platform, and this question would be more topical in a
group devoted to your platform. The answer for *nix is different from
the answer for Windows, which is different from the answer for VMS,
etc.
"John Bode" <jo*******@my-deja.com> wrote in message
news:43**************************@posting.google.c om... "Profetas" <xu*****@yahoo.com> wrote in message
news:<e4******************************@localhost.t alkaboutprogramming.com>... 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.
Lovely. However, curses is not a part of the standard C library, and is not a part of every C implementation out there (I don't think you're going to find curses in MSVC). curses is an extension, provided by a specific implementation.
C does not provide high-level (built-in) support for reading individual keystrokes; this is something that's specific to your particular platform, and this question would be more topical in a group devoted to your platform. The answer for *nix is different from the answer for Windows, which is different from the answer for VMS, etc.
Mr. OP--
Might you be so kind as to provide the text to the non-Standard header file
in question? Around here, it seems to be the punchline to some joke I don't
know. MPJ
P.S. Honestly it sounds like Harry Potter. Isn't Migwetch one of the
fraternities in which W was smart?
Merrill & Michele <be********@comcast.net> scribbled the following: "John Bode" <jo*******@my-deja.com> wrote in message news:43**************************@posting.google.c om... "Profetas" <xu*****@yahoo.com> wrote in message news:<e4******************************@localhost.t alkaboutprogramming.com>... > NAME > getch, wgetch, mvgetch, mvwgetch, ungetch, has_key - get (or > push back) > characters from curses terminal keyboard > > SYNOPSIS > #include <curses.h>
(snip)
Lovely. However, curses is not a part of the standard C library, and is not a part of every C implementation out there (I don't think you're going to find curses in MSVC). curses is an extension, provided by a specific implementation.
C does not provide high-level (built-in) support for reading individual keystrokes; this is something that's specific to your particular platform, and this question would be more topical in a group devoted to your platform. The answer for *nix is different from the answer for Windows, which is different from the answer for VMS, etc.
Mr. OP--
Might you be so kind as to provide the text to the non-Standard header file in question? Around here, it seems to be the punchline to some joke I don't know. MPJ
Merely having the header file won't help you. Header files don't contain
code for functions - merely definitions. The actual code is stored in
libraries, which aren't necessarily portable across implementations.
This is all explained in the comp.lang.c FAQ.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:cm**********@oravannahka.helsinki.fi... Merrill & Michele <be********@comcast.net> scribbled the following: Might you be so kind as to provide the text to the non-Standard header
file in question? Around here, it seems to be the punchline to some joke I
don't know. MPJ
Merely having the header file won't help you. Header files don't contain code for functions - merely definitions.
Declarations. But you knew that. :-)
-Mike
Mike Wahler <mk******@mkwahler.net> scribbled the following: "Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message news:cm**********@oravannahka.helsinki.fi... Merrill & Michele <be********@comcast.net> scribbled the following: > Might you be so kind as to provide the text to the non-Standard header file > in question? Around here, it seems to be the punchline to some joke I don't > know. MPJ Merely having the header file won't help you. Header files don't contain code for functions - merely definitions.
Declarations. But you knew that. :-)
Yes. Dammit Jim, I mean Mike, those words are too similar. In Finnish
"definition" is "määritelmä" and "declaration" is "julistus". It would
be so much better if we all spoke Finnish here. =)
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"No, Maggie, not Aztec, Olmec! Ol-mec!"
- Lisa Simpson MPJ: Might you be so kind as to provide the text to the non-Standard
header file > in question? Around here, it seems to be the punchline to some joke
I don't know.
"Joona I Palaste: Merely having the header file won't help you. Header
files don't contain code for functions - merely definitions.
Mike Wahler : Declarations. But you knew that. :-)
Joona: Yes. Dammit Jim, I mean Mike, those words are too similar. In
Finnish "definition" is "määritelmä" and "declaration" is "julistus". It would be so much better if we all spoke Finnish here. =)
Your use of dammit jim does not follow the standard prototype. It always
goes, "Dammit Jim, I'm a doctor not a ...." And if we switch languages in
clc, it's not going to be one where Pop has the drop on us. MPJ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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++.
|
by: aurgathor |
last post by:
Howdy,
What would be the equivalent of getch() using iostream?
My current code is:
cout << "\nPress <Enter> to continue...";
getch();
but <conio.h> is not kosher for the C++ class.
|
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...
|
by: Ratheesh Kumar |
last post by:
My doubt is on the working of getch() function based on the following observations
1) if the pressed key has an ascii code,only that can be read using a single call to getch()
2) if the key has...
| |
by: simnav |
last post by:
In the following code something strange happens ! If I keep pressed any
of ALT+Arrow, keys, they are extracted two times from buffer then getch
seems to stop; if I release and press again ALT+arrow...
|
by: Sankar |
last post by:
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.
...
|
by: Michele 'xjp' |
last post by:
Hi there,
I am using a POSIX-compliant system, Cygwin on Windows.
I need the features of conio.h's getch() and clrscr(), but I can't
compile programs with #include <conio.h(since conio.h is NOT...
|
by: fuzhen |
last post by:
If I want to "press any key to continue" in Windows, I can use getch()
But the getch() isn't a standard C function
So what should I to do in Linux?
|
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,...
|
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...
| |
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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: 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...
|
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...
|
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...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |