Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <signal.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <termios.h>
- #include <unistd.h>
- #include <string.h>
- #define MAXTAB 5
- volatile sig_atomic_t keep_going = 1;
- int getch()
- {
- struct termios oldtc, newtc;
- int ch;
- tcgetattr(STDIN_FILENO, &oldtc);
- newtc = oldtc;
- newtc.c_lflag &= ~(ICANON | ECHO);
- tcsetattr(STDIN_FILENO, TCSANOW, &newtc);
- ch=getchar();
- tcsetattr(STDIN_FILENO, TCSANOW, &oldtc);
- return ch;
- }
- void catch_alarm (int sig)
- {
- keep_going = 0;
- signal (sig, catch_alarm);
- }
- void do_stuff (char *temp)
- {
- int i;
- int j=0;
- char ch;
- ch = getch();
- while(ch!=10)
- {
- printf("*");
- temp[j]=ch;
- j++;
- ch = getch();
- }
- //puts ("Doing stuff while waiting for alarm....");
- }
- int main (void)
- {
- char temp[MAXTAB];
- char pass[] = "inter";
- /******************************/
- /*******************************/
- signal (SIGALRM, catch_alarm);
- alarm (5);
- while (keep_going)
- do_stuff (temp);
- if(strcmp(temp, pass) == 0)
- printf("Haslo jest poprawne");
- else
- printf("haslo jest niepoprawne");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement