I'm trying to write a program that uses the arrow keys to choose an option and than select it with the enter key. The problem is, and i've researched this, is that getchar() needs a (second) enter keystroke to choose the option. I haven't found a solution to my problem while researching this. Here's (part of) the code:
..... system("/bin/stty --file=/dev/tty -icanon"); ch = getchar(); switch (ch) { case 66: // up arrow value += 1; if (value > numOptions-1) { value = numOptions-1; } break; case 65: // down arrow value -= 1; if (value < 0) { value = 0; } break; } } while (ch != 13); // Our termination cond: then hit enter. .... const char *options2[]={"option1", "option2", "option3", "option4"}; const char *selected2[]={"OPTION1", "OPTION2", "OPTION3", "OPTION4"}; .... Ok. I finally solved this. Apparently, a text file was causing the program to somehow not parse the carriage return properly. Getchar does work, after all. Thanks everyone for your help.