Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <signal.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <termios.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7.  
  8. #define MAXTAB 5
  9.  
  10. volatile sig_atomic_t keep_going = 1;
  11.  
  12. int getch()
  13. {
  14. struct termios oldtc, newtc;
  15. int ch;
  16. tcgetattr(STDIN_FILENO, &oldtc);
  17. newtc = oldtc;
  18. newtc.c_lflag &= ~(ICANON | ECHO);
  19. tcsetattr(STDIN_FILENO, TCSANOW, &newtc);
  20. ch=getchar();
  21. tcsetattr(STDIN_FILENO, TCSANOW, &oldtc);
  22.  
  23. return ch;
  24. }
  25.  
  26. void catch_alarm (int sig)
  27. {
  28. keep_going = 0;
  29. signal (sig, catch_alarm);
  30. }
  31.  
  32. void do_stuff (char *temp)
  33. {
  34. int i;
  35. int j=0;
  36.  
  37. char ch;
  38. ch = getch();
  39.  
  40. while(ch!=10)
  41. {
  42. printf("*");
  43. temp[j]=ch;
  44. j++;
  45. ch = getch();
  46. }
  47. //puts ("Doing stuff while waiting for alarm....");
  48. }
  49.  
  50. int main (void)
  51. {
  52. char temp[MAXTAB];
  53. char pass[] = "inter";
  54.  
  55. /******************************/
  56. /*******************************/
  57.  
  58. signal (SIGALRM, catch_alarm);
  59. alarm (5);
  60.  
  61. while (keep_going)
  62. do_stuff (temp);
  63.  
  64. if(strcmp(temp, pass) == 0)
  65. printf("Haslo jest poprawne");
  66. else
  67. printf("haslo jest niepoprawne");
  68.  
  69. return EXIT_SUCCESS;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement