branch_JL #1

Merged
Jean-Luc NELET merged 2 commits from branch_JL into master 2024-10-15 11:47:32 +02:00
2 changed files with 11 additions and 0 deletions
Showing only changes of commit 8309e24cc7 - Show all commits

BIN
a.out Executable file

Binary file not shown.

11
pendu.c
View File

@ -2,6 +2,8 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
#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++) {