Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I'm trying to port a large CPP project into linux to run on a Raspberry Pi.

One of the files PROG_WIN.CPP allows a user to interrupt the program. I have had to substitute an old Borland header
C++
#include <conio.h>
with
C++
#include <ncurses.h>
which I belive should be able to directly handle the getch call (though I have read getchar should be inserted) but am getting the following error using the command g++ -w -o with the g++ linking:

PROG_WIN.CPP: In function ‘int user_pressed_escape()’:
PROG_WIN.CPP:69:14: error: ‘kbhit’ was not declared in this scope

I'm presuming that there is no function kbhit in the ncurses.h file and therefore no declaration or definition of this function. Is there a quick workaround for inserting an equivalent function to kbhit?

Thanks for any ideas!

Here is the CPP code:



C++
#include <stdio.h>
#include <string.h>
#include <math.h>
//#include <conio.h>
#include <ncurses.h>
#include <ctype.h>
#include <stdlib.h>
#include "const.h"  // System, limitation constants, typedefs, structs
#include "classes.h"  // Includes all class headers
#include "funcdefs.h" // Function prototypes

//extern int show_progress ;	//had to change this
int show_progress ;

void make_progress_window ( char * )
{
   return ;
}

void destroy_progress_window ()
{
   return ;
}

void write_progress ( char *msg )
{
   if (msg == NULL)
      return ;
   printf ( "\n%s", msg ) ;
}

void write_non_progress ( char * )
{
   return ;
}

int user_pressed_escape ()
{
   int key ;

   if (kbhit()) {         // Was a key pressed?
      key = getch () ;    // Read it if so
      while (kbhit())     // Flush key buffer in case function key
         getch () ;       // or key was held down
      return (key == KEY_ESCAPE) ;
      }
   else
      return 0 ;
}
Posted
Updated 5-Mar-15 2:04am
v3
Comments
Richard MacCutchan 5-Mar-15 9:03am    
You would have to write your own implementation, or find the linux alternative. Try a Google search to see if anyone else has a solution.

1 solution

Thanks Richard - I have tried both!

For others with a similar problem; this link seems promising:

http://forums.fedoraforum.org/showthread.php?t=172337[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900