470,849 Members | 1,102 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

g++

Hi all ,
I program under g++ in linux but it seems it doesn't have conio.h and I
want to use getch() and putch()in my program , Can you tell me what I
must do?
thanks

Apr 25 '06 #1
4 5318
adc++ said:
Hi all ,
I program under g++ in linux but it seems it doesn't have conio.h
Right. conio.h is not part of the C language; it is an extension provided by
some MS-DOS (and, later, Windows) implementations.
and I
want to use getch() and putch()in my program , Can you tell me what I
must do?


putch() is easy:

int putch(int ch)
{
int e = putchar(ch);
fflush(stdout);
return e;
}

getch() is rather harder. Either put your terminal into raw mode, or bite
the bullet and learn the ncurses library.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 25 '06 #2
adc++ wrote:
Hi all ,
I program under g++ in linux but it seems it doesn't have conio.h and I
want to use getch() and putch()in my program , Can you tell me what I
must do?
thanks


Right, conio.h is not available on linux. It's nonstandard and this
newsgroup only deals with standard C. AFAIK there is no portable
way to implement these functions, so if you really need the same
functionality you can use some library that handles the low-level
terminal stuff for you, such as ncurses, which is offtopic here.

Also, if you program in C, you should use a C compiler. g++ is for
C++, use gcc instead.

/Michael
Apr 25 '06 #3
Richard Heathfield wrote:
adc++ said:
Hi all ,
I program under g++ in linux but it seems it doesn't have conio.h


Right. conio.h is not part of the C language; it is an extension provided by
some MS-DOS (and, later, Windows) implementations.


<snip>

In addition to what Richard said, g++ is a C++ compiler *not* a C
compiler. We only deal with C here not C++.
--
Flash Gordon, living in interesting times.
Web site - http://home.flash-gordon.me.uk/
comp.lang.c posting guidelines and intro:
http://clc-wiki.net/wiki/Intro_to_clc

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Apr 25 '06 #4
adc++ wrote:
Hi all ,
I program under g++ in linux but it seems it doesn't have conio.h and I
want to use getch() and putch()in my program , Can you tell me what I
must do?


Stop using getch() and putch().

If you want similar functionality, check, for example, the curses
(ncurses, etc.) family. Be warned:

1) The functionality of similar-looking or similarly-named functions is
not what you have grown to expect.

2) point (1) arises becauses your <conio.h> functions and those from
<curses.h> or <ncurses.h> are none of them standard. That means they
can do any damn thing your implementer chooses. The C standard is not
controlling.

3) point (2) means that discussions of these are about
implementation-specific details which are properly discussed in a
newsgroup (or mailing list, or technical support) for your
implementation. They do *not* belong in <news:comp.lang.c>.
Apr 25 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by William C. White | last post: by
2 posts views Thread by Albert Ahtenberg | last post: by
3 posts views Thread by James | last post: by
reply views Thread by Ollivier Robert | last post: by
1 post views Thread by Richard Galli | last post: by
4 posts views Thread by Albert Ahtenberg | last post: by
1 post views Thread by inderjit S Gabrie | last post: by
2 posts views Thread by Jack | last post: by
3 posts views Thread by Sandwick | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.