User forums > Using Code::Blocks

conio.h for Windows but not for Linux?

<< < (2/2)

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.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

--- 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;
}

--- End code ---

americast:

--- Quote from: coditoter on August 10, 2014, 08:20:34 pm ---You can also install & use ncurses library.

--- End quote ---
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

--- 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;
}

--- End code ---

--- End quote ---
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|
--- End code ---
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'|
--- End code ---

Gramercy...

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

Navigation

[0] Message Index

[*] Previous page

Go to full version