-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwordle.c
92 lines (84 loc) · 2.36 KB
/
wordle.c
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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_WORD_LENGTH 20
#define MAX_ROUNDS 10
char *toUpper(char *str)
{
int i = 0;
while (str[i] != '\0')
{
str[i] = toupper(str[i]);
i++;
}
return str;
}
int main()
{
int i, j, correct, misplaced;
char myWord[MAX_WORD_LENGTH + 1];
char guess[MAX_WORD_LENGTH + 1];
char clue[MAX_WORD_LENGTH + 1];
int wordLength, roundsLeft;
char yeriyanlisharfler[10];
char boylebirharfyokkardesim[10];
int len;
int len2 = 0;
printf("Kelimeyi giriniz: ");
scanf("%s", myWord);
wordLength = strlen(myWord);
toUpper(myWord);
roundsLeft = MAX_ROUNDS;
memset(clue, '_', wordLength);
while (roundsLeft > 0 && strcmp(clue, myWord) != 0)
{
printf("\n%d tahmin hakkiniz kaldi.\n", roundsLeft);
printf("Bir kelime tahmin ediniz (%d harf): ", wordLength);
scanf("%s", guess);
toUpper(guess);
len2 = 0;
correct = 0;
misplaced = 0;
for (i = 0; i < wordLength; i++)
{
if (guess[i] == myWord[i])
{
clue[i] = myWord[i];
correct++;
}
else
{
for (j = 0; j < wordLength; j++)
{
if (guess[i] == myWord[j])
{
misplaced++;
len = strlen(yeriyanlisharfler);
yeriyanlisharfler[len] = guess[i];
yeriyanlisharfler[len + 1] = '\0';
}
if (((j + 1) == wordLength) && misplaced == 0)
{
boylebirharfyokkardesim[len2] = guess[i];
boylebirharfyokkardesim[len2 + 1] = '\0';
len2++;
}
}
}
}
if (correct == wordLength)
{
printf("Tebrikler, kelimeyi dogru tahmin ettiniz!\n");
return 0;
}
else
{
roundsLeft--;
printf("%s \n", clue);
printf("Yanlis konumda olan harfler: %s\n", yeriyanlisharfler);
printf("Olmayan harfler: %s\n", boylebirharfyokkardesim);
yeriyanlisharfler[0] = '\0';
boylebirharfyokkardesim[0] = '\0';
}
}
}