-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathsinisaaa
96 lines (82 loc) · 1.88 KB
/
sinisaaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define MAX_INCORRECT_GUESSES 6
const char *words[] = {
"hello",
"world",
"apple",
"banana",
"orange",
"grape"
};
int main(void) {
srand(time(NULL));
// Choose a random word from the array
const char *word = words[rand() % (sizeof(words) / sizeof(words[0]))];
int word_length = strlen(word);
char guess[word_length + 1];
memset(guess, '_', word_length);
guess[word_length] = '\0';
int incorrect_guesses = 0;
char letter;
int found;
while (incorrect_guesses < MAX_INCORRECT_GUESSES) {
printf("Word: %s\n", guess);
printf("Enter a letter: ");
scanf(" %c", &letter);
found = 0;
for (int i = 0; i < word_length; i++) {
if (word[i] == letter) {
guess[i] = letter;
found = 1;
}
}
if (found) {
if (strcmp(word, guess) == 0) {
printf("You won! The word was %s\n", word);
return 0;
}
} else {
incorrect_guesses++;
switch (incorrect_guesses) {
case 1:
printf(" O\n");
break;
case 2:
printf(" O\n");
printf(" |\n");
break;
case 3:
printf(" O\n");
printf(" |\n");
printf("/ \\\n");
break;
case 4:
printf(" O\n");
printf(" |\n");
printf("/ \\\n");
printf(" |\n");
break;
case 5:
printf(" O\n");
printf(" |\n");
printf("/ \\\n");
printf(" |\n");
printf("/ \\\n");
break;
case 6:
printf(" O\n");
printf(" |\n");
printf("/ \\\n");
printf(" |\n");
printf("/ \\\n");
printf(" |\n");
break;
}
}
}
printf("You lost! The word was %s\n", word);
return 0;
}