ARCHIVED: Using C, how can I read a single character as input without pressing the Enter key?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

In C, the curses (cursor control for C) package has a command called cbreak, which puts the terminal in single character mode. Thus, the getchar command will not wait for the end of a line (Enter) to read input.

For information on how to use cbreak and other curses commands, at the Unix prompt, enter man curses or man cbreak.

When using curses, you must include <curses.h>, and link by entering:

  cc myfile.c -lcurses

At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux or Unix at IU.

This is document abch in the Knowledge Base.
Last modified on 2018-01-18 09:03:50.