Ask coding questions

← Back to all posts
Why do i get an error undefined reference to `getche'
kallyas (0)

I'm using clang-7 on 16.04.1-Ubuntu LTS. I get this warning: implicit declaration of function 'getche'
is invalid in C99 [-Wimplicit-function-declaration]

followed by this error error: undefined reference to `getche'

What could be wrong?

Had to define those functions
added this code

static struct termios old, current;

/* Initialize new terminal i/o settings */
void initTermios(int echo) 
 tcgetattr(0, &old); /* grab old terminal i/o settings */
 current = old; /* make new settings same as old settings */
 current.c_lflag &= ~ICANON; /* disable buffered i/o */
 if (echo) {
     current.c_lflag |= ECHO; /* set echo mode */
 } else {
     current.c_lflag &= ~ECHO; /* set no echo mode */
 tcsetattr(0, TCSANOW, &current); /* use these new terminal i/o settings now */

/* Restore old terminal i/o settings */
void resetTermios(void) 
 tcsetattr(0, TCSANOW, &old);

/* Read 1 character - echo defines echo mode */
char getch_(int echo) 
 char ch;
 ch = getchar();
 return ch;

/* Read 1 character without echo */
char getch(void) 
 return getch_(0);

/* Read 1 character with echo */
char getche(void) 
 return getch_(1);
s1f2z3 (0)

idk if u still care or not ,but the code really have a lot of problems
if u care i can tell u what did i find (i mean problems cuz idk this type of coding)

Highwayman (1482)

It looks like you fixed it, cause it works for me..

kallyas (0)

@Highwayman Yes! Found out later!

kallyas (0)

@Highwayman But still I don't get the expected result! On Listing Records and prompt to add another record, delete another record or modify another record

Highwayman (1482)

@kallyas hum... I’m not familiar with termios, but I think there’s a different struct your supposed to change but idk. :/