[solved] GNU compiler and conio.h

Questions about other topics - please check if your question fits better in another category before posting here
Forum rules
Before you post please read this

[solved] GNU compiler and conio.h

Postby KeesA on Mon Feb 11, 2013 6:21 pm

Hallo,
Now I want to run a program which I wrote in C++ for Windows on Linux Mint.
Unfortunally, one of the headerfiles (conio.h) is not supported by GNU :shock:
I tried to use wxWidget in Wine but met some problems.
Now I use Code::Blocks which uses GNU compiler.
The function which I like to keep is getch() or _getch().
The reason is that the user of my program can press any key to continue without pressing <enter> afterwards when I use getch().
Does anybody know how a good alternative?
tnx a lot.
Last edited by KeesA on Mon Apr 08, 2013 7:00 pm, edited 1 time in total.
User avatar
KeesA
Level 2
Level 2
 
Posts: 94
Joined: Wed Jan 09, 2013 8:47 pm

Linux Mint is funded by ads and donations.
 

Re: GNU compiler and conio.h

Postby xenopeek on Mon Feb 11, 2013 7:01 pm

ncurses.h has a getch fuction, the file is in /usr/include/ncurses.h. You need to install ncurses-dev package to get it.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14889
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: GNU compiler and conio.h

Postby KeesA on Mon Feb 11, 2013 7:31 pm

I did already and found out that getch() has to be repleaced by getch.
But when assigning to a char variable, I get an error.

error: invalid conversion from ‘int (*)()’ to ‘char’ [-fpermissive]|

Is this about a function object or function pointer?
Or, I hope, someting less complicated and easy to solve?
User avatar
KeesA
Level 2
Level 2
 
Posts: 94
Joined: Wed Jan 09, 2013 8:47 pm

Re: GNU compiler and conio.h

Postby KeesA on Mon Feb 11, 2013 9:26 pm

Now I know the interpretation of this fault message.
It says that you can't assign a refference to a function to a char.
But when I put () afer getch, I get:

Telebase 3.1 .cpp|| undefined reference to `stdscr'|

What does this mean?
Any thoughts?
User avatar
KeesA
Level 2
Level 2
 
Posts: 94
Joined: Wed Jan 09, 2013 8:47 pm

Re: GNU compiler and conio.h

Postby xenopeek on Tue Feb 12, 2013 3:20 am

Don't know about that, but here is the bit about keyboard handling in the ncurses programming howto, might help: http://www.tldp.org/HOWTO/NCURSES-Progr ... /keys.html
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14889
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: GNU compiler and conio.h

Postby KeesA on Tue Feb 12, 2013 6:30 pm

Thank you for the link.
I found out already, that one thing is importent to use curses or ncurses and that is to link it with your program.
Code::Blocks -> project -> Build options -> Linker settings -> Add
Here I typed: curses and ncurses.
Now I can write: char bar = getch(); without any problems. :D
Unfortunally the program "falls through" the getch statement. :oops:
Maybe someone knows how this can happen (it always worked fine in the Windows Dos box).
At the moment I am searching for the most simple solution to run my program like I did in Windows.
User avatar
KeesA
Level 2
Level 2
 
Posts: 94
Joined: Wed Jan 09, 2013 8:47 pm

Re: GNU compiler and conio.h

Postby KeesA on Wed Feb 13, 2013 11:28 pm

Problem is solved.
I found this:

http://stackoverflow.com/questions/7469 ... e-in-linux

and it works!

Only, in addition to that, I had to write cin.ignore(); before the getch(); statements.
When getch(); is in a loop or recursive function, cin.ignore(); has to be put above that and not in the looping.
User avatar
KeesA
Level 2
Level 2
 
Posts: 94
Joined: Wed Jan 09, 2013 8:47 pm

Linux Mint is funded by ads and donations.
 

Return to Other topics

Who is online

Users browsing this forum: steviejay and 4 guests