main.c 562 B

1234567891011121314151617181920212223242526272829303132
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <termios.h>
  5. int main(int argc, char *argv[], char *envp[]) {
  6. struct termios term, term_orig;
  7. if(tcgetattr(0, &term_orig)) {
  8. printf("tcgetattr failed\n");
  9. exit(-1);
  10. }
  11. term = term_orig;
  12. term.c_lflag &= ~ICANON;
  13. term.c_lflag |= ECHO;
  14. term.c_cc[VMIN] = 0;
  15. term.c_cc[VTIME] = 0;
  16. if (tcsetattr(0, TCSANOW, &term)) {
  17. printf("tcsetattr failed\n");
  18. exit(-1);
  19. }
  20. char ch;
  21. while (1) {
  22. if (read(0, &ch, 1) > 0)
  23. printf(" %d\n", ch);
  24. }
  25. return 0;
  26. }