Author Topic: conio.h for Windows but not for Linux?  (Read 13291 times)

Offline americast

  • Single posting newcomer
  • *
  • Posts: 4
conio.h for Windows but not for Linux?
« on: August 06, 2014, 02:27:30 pm »
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

  • Guest
Re: conio.h for Windows but not for Linux?
« Reply #1 on: August 06, 2014, 02:51:37 pm »
You may find why it's not working on GNU / Linux here:

conio.h

Offline americast

  • Single posting newcomer
  • *
  • Posts: 4
Re: conio.h for Windows but not for Linux?
« Reply #2 on: August 06, 2014, 03:24:03 pm »
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

  • Guest
Re: conio.h for Windows but not for Linux?
« Reply #3 on: August 06, 2014, 03:49:25 pm »
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.

Offline americast

  • Single posting newcomer
  • *
  • Posts: 4
Re: conio.h for Windows but not for Linux?
« Reply #4 on: August 06, 2014, 03:53:49 pm »
Is it possible to integrate mingw compiler with code blocks in linux?

Gramercy...

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: conio.h for Windows but not for Linux?
« Reply #5 on: August 06, 2014, 10:16:35 pm »
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.codeblocks.org/index.php?topic=3343.0


greetings

Offline coditoter

  • Single posting newcomer
  • *
  • Posts: 8
Re: conio.h for Windows but not for Linux?
« Reply #6 on: August 10, 2014, 08:20:34 pm »
You can also install & use ncurses library.

Offline jcfuller

  • Single posting newcomer
  • *
  • Posts: 3
Re: conio.h for Windows but not for Linux?
« Reply #7 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
Code
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;
}

Offline americast

  • Single posting newcomer
  • *
  • Posts: 4
Re: conio.h for Windows but not for Linux?
« Reply #8 on: August 11, 2014, 02:05:05 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?

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
Code
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;"):
Code
/usr/include/c++/4.8/conio.h|470|error: missing terminating " character|
I tried removing " form the end and it resulted in these errors:
Code
final.cpp|| undefined reference to `stdscr'|
final.cpp|| undefined reference to `wgetch'|

Gramercy...

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: conio.h for Windows but not for Linux?
« Reply #9 on: August 11, 2014, 05:21:01 pm »
Topic locked, because it violates our forum rules.
No relation to Code::Blocks or development of Code::Blocks !!