News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

conio.h for Windows but not for Linux?

Started by americast, August 06, 2014, 02:27:30 PM

Previous topic - Next topic

americast

Hi all,
  I have found that the windows version of code::blocks supports the header file <conio.h> and its functions (like getch() etc.). I have also installed a copy in my Linux distro (OpenSUSE 13.1) with GNU GCC G++ (C++) compiler which does not offer support for the same. Is it possible to incorporate conio.h into Linux? This is because some of the programs using conio.h is not working on my Linux system...

Gramercy...

ToApolytoXaos

You may find why it's not working on GNU / Linux here:

conio.h

americast

Thanx...
So, how do I get such functions working on my linux system? Is there any alternative? Functions such as getch() and kbhit() are really quite useful...

Gramercy...

ToApolytoXaos

You should get yourself a C book, preferably an ANSI C one, and learn more about libraries like stdio.h.

For instance, http://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html explains things like getchar() and putchar() that do what you want to accomplish that also is POSIX compliant, therefore portable by standard.

americast

Is it possible to integrate mingw compiler with code blocks in linux?

Gramercy...

BlueHazzard

for cross compiling windows programs on linux with mingw? For sure! But you wouldn't be able to run them on linux natively... only with the help of wine.

http://wiki.codeblocks.org/index.php?title=Code::Blocks_and_Cross_Compilers or http://forums.next.codeblocks.org/index.php?topic=3343.0


greetings

coditoter

You can also install & use ncurses library.

jcfuller

I have used this as a replacement for the windows _getch.
You will need to include term.h on Linux.
Be aware, I understand there are problems with term.h inclusion and g++ ????
James

int _getch_(int waitkey)
{
  struct termios initial_settings, new_settings;"
  unsigned char ch;
  tcgetattr(0,&initial_settings);
  new_settings = initial_settings;
  new_settings.c_lflag &= ~ICANON;
  new_settings.c_lflag &= ~ECHO;
  new_settings.c_lflag &= ~ISIG;
  new_settings.c_cc[VMIN] = waitkey;
  new_settings.c_cc[VTIME] = 0;
  tcsetattr(0, TCSANOW, &new_settings);

    //read(0,&ch,1);
    ch = getchar();
  tcsetattr(0, TCSANOW, &initial_settings);
  return ch;
}

americast

Quote from: coditoter on August 10, 2014, 08:20:34 PM
You can also install & use ncurses library.
I have got the ncurses library. Simply using #include <ncurses.h> does not work. Should I include only curses.h to get getch() working?

Quote from: jcfuller on August 11, 2014, 11:32:18 AM
I have used this as a replacement for the windows _getch.
You will need to include term.h on Linux.
Be aware, I understand there are problems with term.h inclusion and g++ ????
James

int _getch_(int waitkey)
{
  struct termios initial_settings, new_settings;"
  unsigned char ch;
  tcgetattr(0,&initial_settings);
  new_settings = initial_settings;
  new_settings.c_lflag &= ~ICANON;
  new_settings.c_lflag &= ~ECHO;
  new_settings.c_lflag &= ~ISIG;
  new_settings.c_cc[VMIN] = waitkey;
  new_settings.c_cc[VTIME] = 0;
  tcsetattr(0, TCSANOW, &new_settings);

    //read(0,&ch,1);
    ch = getchar();
  tcsetattr(0, TCSANOW, &initial_settings);
  return ch;
}

I am getting an error in the first line (struct termios initial_settings, new_settings;"): /usr/include/c++/4.8/conio.h|470|error: missing terminating " character|
I tried removing " form the end and it resulted in these errors:
final.cpp|| undefined reference to `stdscr'|
final.cpp|| undefined reference to `wgetch'|


Gramercy...

Jenna

Topic locked, because it violates our forum rules.
No relation to Code::Blocks or development of Code::Blocks !!