diff --git a/a.out b/a.out new file mode 100755 index 0000000..91c1674 Binary files /dev/null and b/a.out differ diff --git a/pendu.c b/pendu.c index 1b0cfd6..f06acbb 100644 --- a/pendu.c +++ b/pendu.c @@ -2,6 +2,8 @@ #include #include #include +#include +#include #define MAX_WORDS 14 #define MAX_TRIES 6 @@ -35,6 +37,11 @@ void display_hangman(int tries) { } } +void alarm_handler(int sig) { + printf("\nTrop tard ! Vous avez dépassé les 30 secondes.\n"); + exit(1); +} + int main() { srand(time(NULL)); const char *word = words[rand() % MAX_WORDS]; @@ -48,12 +55,16 @@ int main() { } guessed[word_length] = '\0'; + signal(SIGALRM, alarm_handler); + while (tries < MAX_TRIES && guessed_correctly < word_length) { printf("\nMot à deviner : %s\n", guessed); display_hangman(tries); char guess; + alarm(30); printf("Entrez une lettre : "); scanf(" %c", &guess); + alarm(0); int found = 0; for (int i = 0; i < word_length; i++) {