Advertisement
Guest User

does not work, with syntax highlighting

a guest
Feb 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. //C code that does not work (yet), with syntax highlighting.
  2. //$ cat getch.c
  3. #include <stdio.h>
  4. #include <ncurses.h>
  5. #include <unistd.h>  /* only for sleep() */
  6.  
  7. int kbhit(void)
  8. {
  9.     int ch = getch();
  10.  
  11.     if (ch != ERR) {
  12.         ungetch(ch);
  13.         return 1;
  14.     } else {
  15.         return 0;
  16.     }
  17. }
  18.  
  19. main()
  20. {
  21. int i = 0;
  22.  
  23. initscr();
  24.  
  25. cbreak();
  26. noecho();
  27. nodelay(stdscr, TRUE);
  28.  
  29. scrollok(stdscr, TRUE);
  30.  
  31.  
  32. while (1) {
  33.         if (kbhit()) {
  34.             printw("Key pressed! It was: %d\n", getch());
  35.             refresh();
  36.         break;
  37.         } else {
  38.             printf("Numero: %d ",i);
  39.             refresh();
  40.             sleep(1);
  41.         i++;
  42.         }
  43.     printf("%d ", i);
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement