g++

A

adc++

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
 
R

Richard Heathfield

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

Michael Brennan

adc++ said:
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
 
F

Flash Gordon

Richard said:
adc++ said:


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
 
M

Martin Ambuhl

adc++ said:
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>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top