Conio h чем заменить

от admin

Conio h чем заменить

Q: Is there a getch() (from conio) equivalent on Linux/UNIX?

A: No. But it’s easy to emulate:

#include <stdio.h>
#include <termios.h>
#include <unistd.h>

int mygetch( ) struct termios oldt,
newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &=

This code sets the terminal into non-canonical mode, thus disabling line buffering, reads a character from stdin and then restores the old terminal status. For more info on what else you can do with termios, see «man termios».
There’s also a «getch()» function in the curses library, but it is /not/ equivalent to the DOS «getch()» and may only be used within real curses applications (ie: it only works in curses «WINDOW»s)..

Analog of conio.h

How can I replace conio.h? Unlike other similar functions, it does not require pressing Enter. Are there any analogues from the standard library?

1 Answer 1

it does not require pressing Enter

NCurses doesn’t require pressing Enter too. This is your code based on NCurses which allows that:

To compile don’t forget to include "-lncurses", eg:

igroglaz's user avatar

    The Overflow Blog
Related
Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.3.11.43304

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Is there any library similar to <conio.h>?

I used the IDE DEV C++ to compile C programs on Windows and I used the libraries and , but now I use Ubuntu and downloaded the Codeblocks, but it does not have these libraries. I just wanted to use some function similar to getch(), which is present in the library conio. Is there any similar library? And if there is how do I install?

Patterson's user avatar

4 Answers 4

Note that this is only compatible file. I recommend to shift on curses.h file, which has lot many things, which are absent in conio.h file.

Читать:
Как выключить компьютер через python

the best way, is create a symlink between curses.h and conio.h like:

then you can use

if you don’t have curses.h

Here is a possible solution:

  1. From https://sourceforge.net/projects/hlanguage/files/Source/include/conio.h/download download the 1.1 KB conio.h file
  2. Save or copy the file to the directory /usr/include
  3. Then from https://sourceforge.net/projects/hlanguage/files/Source/include/_mingw.h/download download the 3.8KB _mingw.h file which conio.h depends on.
  4. Save the _mingw.h file to the same location as the conio.h file.

Do not dump these files to your present project directory, they will not work. Besides these are general compiler libraries that you may need to compile other projects, so better to make them available to the compiler and not the project.

I am using an Android handheld, if you are on PC please revise this response with wget and precise download links.

Alternative for the Headerfile <conio.h>?

Hello, iam using Linux and <conio.h> is not in the standardlib. Therefore i cant use it :/. Ive been looking around the internet for alternatives but every thread or post is like 7 years old at minimum. Nothings works and documentation is missing. Hopefully someone can help. Thanks in advance 🙂

What exactly do you need from that header?

conio.h was part of the dos c library back in the day. in the year of our lord 2019, it's pretty much only worth mentioning as a historical note. if you want, like, a real library for terminal i/o, you should probably use ncurses. but, given that conio.h only ever had like 8 pretty trivial functions, i don't see what you'd want to use it for at all. other than kbhit , which you should probably avoid anyway, all of the functions in that header were just versions of the stdio.h i/o operators which operate on the console stream instead of stdin or stdout. on a linux system, unless you do something to change the behavior of stdin and stdout, the functions in stdio.h will do the same things as the versions that were in conio.h .

Related Posts