Receive character in C

Asked

Viewed 81 times

0

How do I do a function in C equal to the function Readkey of Pascal or equal to the function Lastkey of the old man Clipper? I want to receive only one character separately for each key pressed. Create menus, receive key ESC, etc. Thanks in advance.

  • 1

    Pascal’s Readkey equivalent is Clipper’s Inkey, not Lastkey. Which of the two behaviors do you want?

1 answer

0

In C you need an external library to do this. The default language does not define a way to do this. An external library that displays this feature is ncurses; there must be others, but I don’t know them.

Example taken from NCURSES Programming HOWTO and with some changes to my taste:

#include <ncurses.h>

int main(void) {    
    initscr();                /* Start curses mode              */
    printw("Hello, World!");  /* Print Hello. World!            */
    refresh();                /* Print it on to the real screen */
    getch();                  /* Wait for user input            */
    endwin();                 /* End curses mode                */
    return 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.