94

Possible Duplicate:
How to implement getch() function of C in Linux?

What is the equivalent Linux version of the conio.h header file from MS-DOS?

Is there a way to replace its functionality? e.g. getch()

I'm using gcc and the text editor Geany to compile C code.

janniks
  • 2,942
  • 4
  • 23
  • 36

4 Answers4

124

conio.h is a C header file used with old MS-DOS compilers to create text user interfaces. Compilers that target other operating systems, such as Linux-based, 32-bit Windows and OS/2, provide equivalent functionality through other header files and libraries.

The #include <curses.h> will give you almost all of the functionality provided by conio.h.

"ncurses" needs to be installed in the first place.

If you use the Apt package manager:

sudo apt-get install libncurses5-dev libncursesw5-dev

If you use rpm:

sudo yum install ncurses-devel ncurses

For getch, take a look at the "NCURSES Programming HOWTO" article.

Armen Michaeli
  • 8,625
  • 8
  • 58
  • 95
Sangeeth Saravanaraj
  • 16,027
  • 21
  • 69
  • 98
  • 11
    I am getting error 'fatal error: curses.h: No such file or directory' what should i do ? – sumitkanoje Mar 26 '13 at 12:41
  • 4
    @kanojesumit That means that a curses library is not installed. It is not a standard library. You will need to find it online (for instance Ncurses is a free GPL implementation). – oligofren Jun 29 '13 at 16:10
  • Programs that use `curses` or `ncurses` normally take over the entire (text) screen, which may or may not be what you want. – Keith Thompson Oct 10 '13 at 23:57
  • Even i am getting error permutation.c:2:19: fatal error: curses.h: No such file or directory #include ^ compilation terminated. – Vinay Guru Jul 13 '15 at 06:33
  • 1
    Everyone says curses but the issue with curses is that it MUST take over your console environment. If you already have a console program, you need to rewrite the whole thing in curses to be consistant, as curses manages its own screen. Why can't we just port conio? – Dmytro Apr 12 '16 at 18:50
26

The original conio.h was implemented by Borland, so its not a part of the C Standard Library nor is defined by POSIX.

But here is an implementation for Linux that uses ncurses to do the job.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
8

That is because it does not exist, since it is bounded to Windows.

Use the standard functions from <stdio.h> instead, such as getc

The suggested ncurses library is good if you want to write console-based GUIs, but I don't think it is what you want.

Ottavio Campana
  • 4,088
  • 5
  • 31
  • 58
7

A popular Linux library which has similar functionality would be ncurses.

Antoine Gersant
  • 526
  • 4
  • 7