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? 16 3436
fuzhen wrote:
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?
"Press any key other than the one you will press next."
"Press ENTER" is also a candidate.
--
Eric Sosman es*****@ieee-dot-org.invalid
On Jun 12, 8:56 am, fuzhen <fuc...@gmail.c omwrote:
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?
getch() is a non-standard extension which does not echo the character
entered. In standard C, you can use getchar(), getc(), fgetc() ....
All these functions read a character. In Windows, the common practice
is to use getch() for halting the program. Both conio.h and getch()
are non-standard extensions. To be on the safer side, you can always
use getchar() if you are trying to write portable code.
fuzhen wrote:
If I want to "press any key to continue" in Windows, I can use
getch()
Why would you want to do that?
Just run your program from a shell/dos window and avoid messy
functions that just clutter your code and render it next to useless
for batch scripts.
--
Peter
Eric Sosman <es*****@ieee-dot-org.invalidwrit es:
fuzhen wrote:
>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?
"Press any key other than the one you will press next."
"Press ENTER" is also a candidate.
"Press any key to continue. Press any other key to quit."
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
fuzhen <fu****@gmail.c omwrites:
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?
As Peter Nilsson points out, it's often just not necessary,
particularly if the "press any key to continue" occurs just before the
program terminates.
If you want the program to continue immediately after the user presses
*any* key, there's no portable solution, though there are various
non-portable solutions. See question 19.1 of the comp.lang.c FAQ,
<http://c-faq.com/>.
If you'll settle for requiring the user to press <return(or <enter>,
or whatever you want to call it), you can have a loop that reads and
discards characters until it sees a '\n' (or EOF).
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
fuzhen wrote:
>
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?
Note the addition of periods to terminate sentences.
Try "Press 'return' to continue" followed by "fflush(stdin); " and
"getchar(); ". You can substitute 'Enter' for 'return' if you
wish. You can also substitute skipln(stdin) for getchar() (which
will be cleaner), where:
int skipln(FILE *f) {
int ch;
while ((EOF != (ch = getc(f))) && ('\n' != ch)) continue;
return ch;
} /* skipln */
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com **
CBFalconer wrote:
fuzhen wrote:
>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?
Note the addition of periods to terminate sentences.
carriage returns are also an acceptable way to indicate natural breaks
in writing.
Try "Press 'return' to continue" followed by "fflush(stdin); "
Hmm. Why try undefined behaviour?
On 12 Jun 2008 at 3:56, fuzhen wrote:
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?
In most Linux shells, terminal input is usually line-buffered, so your
program won't find out about character presses by default until the user
presses return. Your main choices are:
1) fiddle with functions in termios.h to switch the terminal to
unbuffered mode, then call getchar(), then set the terminal back to
buffered mode
2) make a (n)curses application and use getch()
3) settle for "press return to continue" and then do something to read a
line, e.g. system("read");
On Jun 12, 10:49 am, Mark McIntyre <markmcint...@T ROUSERSspamcop. net>
wrote:
CBFalconer wrote:
fuzhen wrote:
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?
Note the addition of periods to terminate sentences.
carriage returns are also an acceptable way to indicate natural breaks
in writing.
Try "Press 'return' to continue" followed by "fflush(stdin); "
Hmm. Why try undefined behaviour?
I think he meant fflush(stdout), so "Press 'return' to continue" is
actually written to the stdout stream.
I also believe that it becomes more clear when you read the rest of
his post (ie, the part you snipped) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 encountered. I need
some help.
|
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 not an ascii code then the first call to getch() returns a zero and ,if we made a second call, it will return the scan code with out an additional key...
|
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 nothing changes:
the only way to exit from this condition is press another key a single
time.
What seems to happen is that kbhit say some keys are...
| |
by: mdh |
last post by:
I am just trying to figure out if this is intended behavior, or whether
I am missing something...(probably the latter).
The example given (p96, K&R) is meant to illustrate pointer behavior.
K&R say the example "break(s) a stream of characters into integer
values"
The relevant code is: ( I think)
|
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.
I would appreciate if somone suggests me proven solution to this.
thanks in advance
Sankar
|
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 POSIX).
I tried to implement myself clrscr() with system("cls"), but the program
compiles ok, but during the running it will show:
sh: cls:...
|
by: Ananthu |
last post by:
Hi
In my college they have given me the following codings for implementing linker function.
Codings:
#include<stdio.h>
#include<conio.h>
void cursoron();
void cursoroff();
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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...
| |
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. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
|
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...
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |