This commit is contained in:
Nathan BOUZON 2024-10-15 11:47:35 +02:00
parent 2361771f21
commit 3e92ebda4a
2 changed files with 45 additions and 3 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.out

47
pendu.c
View File

@ -20,7 +20,9 @@ const char *words[MAX_WORDS] = {
"gyroscope", "gyroscope",
"periclitation", "periclitation",
"susurrer", "susurrer",
"eclesiastique" "eclesiastique",
"de",
"a"
}; };
void display_hangman(int tries) { void display_hangman(int tries) {
@ -35,14 +37,53 @@ void display_hangman(int tries) {
} }
} }
int main() { char *hidden_word(int length_choice) {
srand(time(NULL)); srand(time(NULL));
const char *word = words[rand() % MAX_WORDS]; char word = words[rand() % MAX_WORDS];
int word_length = strlen(word); int word_length = strlen(word);
int stay_length = length_choice;
char *total_word;
int number_of_word = 0;
int total_length = word_length;
for(int y=0; word_length > length_choice; y++){
word = *words[rand() % MAX_WORDS];
word_length = strlen(word);
}
total_word = word;
for(int y=0; word_length > stay_length; y++){
word = *words[rand() % MAX_WORDS];
word_length = strlen(total_word);
if(stay_length >= word_length){
total_word = word +'\0'+ *total_word;
total_length = strlen(total_word);
stay_length = total_length - length_choice;
}
}
return total_word;
}
int main() {
int length_choice = 26;
printf("Entrez la difficulté (Taille maximum du mot à deviner) : ");
scanf(" %d", &length_choice);
char *word = hidden_word(length_choice);
int word_length = strlen(word);
char guessed[word_length]; char guessed[word_length];
int tries = 0; int tries = 0;
int guessed_correctly = 0; int guessed_correctly = 0;
for (int i = 0; i < word_length; i++) { for (int i = 0; i < word_length; i++) {
guessed[i] = '_'; guessed[i] = '_';
} }