Portál AbcLinuxu, 12. května 2025 06:33
getch()
, ktora ked sa (podla manualu) vola v 'no-delay' mode(nastavenie funkciou nodelay(...)
) , tak vracia hodnotu ERR
. Tymto by sa to mohlo dat otestovat ... . Pre uplnost dodavam odkazy na man stranky : man ncurses, man nodelay, man getch, ... .
Hesiod
#include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <termios.h> /* Use this variable to remember original terminal attributes. */ struct termios saved_attributes; void reset_input_mode(void) { tcsetattr(STDIN_FILENO, TCSANOW, &saved_attributes); } void set_input_mode(void) { struct termios tattr; /* Make sure stdin is a terminal. */ if (!isatty(STDIN_FILENO)) { fprintf(stderr, "Not a terminal.\n"); exit(EXIT_FAILURE); } /* Save the terminal attributes so we can restore them later. */ tcgetattr(STDIN_FILENO, &saved_attributes); atexit(reset_input_mode); /* Set the funny terminal modes. */ tcgetattr(STDIN_FILENO, &tattr); tattr.c_lflag &= ~(ICANON|ECHO); /* Clear ICANON and ECHO. */ tattr.c_cc[VMIN] = 0; tattr.c_cc[VTIME] = 0; tcsetattr(STDIN_FILENO, TCSAFLUSH, &tattr); } int main(void) { char c; long int i = 0; set_input_mode(); puts("Press Enter"); while (1) { read(STDIN_FILENO, &c, 1); if (c == '\n') /* `Enter' */ break; i++; } printf("i == %ld\n", i); return EXIT_SUCCESS; }
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.