-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hangman.c
96 lines (96 loc) · 2.24 KB
/
Hangman.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
93
94
95
96
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int i,j,result=0,strike=8,k=0;
char word[10],guess[10],a,end,let;
printf("\nEnter the word Player1::");
gets(word);
system("clear");
int len=strlen(word);
printf("\nYour word is::");
char new[len],unique[len],check[8];
strcpy(unique,word);
for(i=0;i<len;i++)
{
new[i]='_';
printf("_ ");
}
a:
printf("\nenter Y to guess word or N to guess letter::");
char ch;
scanf("%s",&ch);
if(ch=='y' || ch=='Y')
{
printf("\nguess the word::");
scanf("%s",&guess);
if(strcmp(guess,unique)==0)
{
result=1;
goto end;
}
else
{
result=0;
printf("\nyour guess is wrong");
strike--;
printf("\nYou have %d strikes left",strike);
if(strike==0)
goto end;
else
goto a;
}
}
else
{
printf("\nGuess the letter::");
scanf("%s",&let);
for(i=0;i<len;i++)
{
if(word[i]==let)
{
new[i]=let;
word[i]=' ';
printf("\nYour guess is correct");
printf("\nYou have %d strikes left",strike);
printf("\nYour word is:: %s",new);
if(strcmp(new,unique)==0)
{
result=1;
goto end;
}
else
goto a;
}
}
for(j=0;j<8;j++)
{
if(check[j]==let)
{
printf("\nDon,t guess the same word again which you have already guessed");
goto a;
}
}
check[k++]=let;
result=0;
printf("\nyour guess is wrong");
strike--;
printf("\nYou have %d strikes left",strike);
printf("\nYour word is:: %s",new);
if(strike==0)
goto end;
else
goto a;
}
end:
if(result==1)
{
printf("\nCONGRATULATION!!!\nYou won the match\nThe word was :: %s",unique);
}
else
{
printf("\nSORRY!!!\nYou loose the match\nThe word was ::%s",unique);
}
return 0;
}