Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: americast on August 06, 2014, 02:27:30 pm

Title: conio.h for Windows but not for Linux?
Post by: americast 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...
Title: Re: conio.h for Windows but not for Linux?
Post by: ToApolytoXaos on August 06, 2014, 02:51:37 pm
You may find why it's not working on GNU / Linux here:

conio.h (http://en.wikipedia.org/wiki/Conio.h)
Title: Re: conio.h for Windows but not for Linux?
Post by: americast 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...
Title: Re: conio.h for Windows but not for Linux?
Post by: ToApolytoXaos 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 (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.
Title: Re: conio.h for Windows but not for Linux?
Post by: americast on August 06, 2014, 03:53:49 pm
Is it possible to integrate mingw compiler with code blocks in linux?

Gramercy...
Title: Re: conio.h for Windows but not for Linux?
Post by: BlueHazzard 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
Title: Re: conio.h for Windows but not for Linux?
Post by: coditoter on August 10, 2014, 08:20:34 pm
You can also install & use ncurses library.
Title: Re: conio.h for Windows but not for Linux?
Post by: 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
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;
}
Title: Re: conio.h for Windows but not for Linux?
Post by: americast 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...
Title: Re: conio.h for Windows but not for Linux?
Post by: Jenna 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 !!